phpwordpress

Get post IDs that contain a search term in wp_posts or in the custom_fields for the ID


I need to return the IDs for all WordPress posts that contain a search term either in the wp_posts fields for that ID or in any of the custom fields that are linked to that ID. I can't think of an SQL query to do this so I'm faced with doing something like using get_post_meta($ID,'') to bring back all the custom fields for an ID, and then searching all of those with strstr().

But searching posts for some content seems like a fairly common thing to do in WordPress development so I'm thinking that WordPress might have something built in to help, or there's a plugin for it.

Does anyone know a good way to do this? Thanks


Solution

  • There's a solution to this at http://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/.