WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a site using Advanced Custom Fields to create and store various bits of relevant info. These need to be included in the main general search, which by default only searches the title and main content.

I've found plenty of info about getting search results based on specific bits of postmeta, but I have an issue with that. There are a potentially unlimited amount of potential fields in postmeta to search.

The solution could either search anything in postmeta or anything with a meta_key that matches this regex: content_section_[0-9]{1,4}_content_.{2,8}

Example meta_keys to match are:


Any way that I can alter the fields searched to include the postmeta would be very much appreciated.

share|improve this question
and the question is? – Naoise Golden Dec 8 '11 at 21:31
Searching in Wordpress doesn't search data from the post meta - it only searches the title and content fields. I'll update the main question to clarify. – Magnakai Dec 9 '11 at 0:53
up vote 2 down vote accepted

If your up for using a plugin, Relevanssi - A Better Search might be worth trying out.

The standard (free) version supports searching post meta.

share|improve this answer

Add this to your plugin or functions.php file of your theme. The example below will include 'your_key' in search. You can include all your keys by repeating the array.

function me_search_query( $query ) {
  if ( $query->is_search ) {
    $meta_query_args = array(
        'key' => 'your_key',
        'value' => $query->query_vars['s'] = '',
        'compare' => 'LIKE',
    $query->set('meta_query', $meta_query_args);
add_filter( 'pre_get_posts', 'me_search_query');
share|improve this answer

I not 100% sure, but to grab all the custom field keys/values for the default search would require a database call using wpdb.

The alternative plugin besides the ones goto10 mentioned are a much simpler solution. Search Everything, WP Custom Fields Search

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.