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 noticed that the content of my custom fields is not in my search results. Is there a good remedy for this?

I could just hardcode my content into page templates but I would like the content to be searchable.


share|improve this question
up vote 2 down vote accepted

You can use an custom plugin for your custom fields

function fb_custom_search_where($where) {
    // put the custom fields into an array
    $customs = array('custom_field1', 'custom_field2', 'custom_field3');

    foreach( $customs as $custom ) {
    $query .= " OR (";
    $query .= "( m.meta_key = '$custom' )";
    $query .= " AND ( m.meta_value  LIKE '{$n}{$term}{$n}' )";
        $query .= ")";

    $where = " AND ({$query}) AND ($wpdb->posts.post_status = 'publish') ";
add_filter( 'posts_where', 'fb_custom_search_where' );

Also you can check the plugin WP Custom Fields Search and you have adhoc an solution.

share|improve this answer
very strange code... $term is empty variable so there will be no results. Also i can bet the $wpdb should be global. strange that this answer was chosen, cause it's not working. – Tommixoft May 19 '12 at 20:26
i think this example was understand from the people, there have ask the question, its only an example. – bueltge May 23 '12 at 7:13
This code does not work at all, beware! – englebip Sep 5 '12 at 19:28
Why, it works on different installs. But it is important, that you change the identifier of the custom fields in the first array. – bueltge Sep 9 '12 at 15:19
It doesn't work, becuase it is assumed that the people using it have, at least, minimal programming knowledge. Should you modify it correctly, it will modify the SQL query appropriately. – Shane Dec 3 '12 at 7:53

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.