Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks.

share|improve this question
add comment

1 Answer

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') ";
    return($where);
}
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
2  
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
add comment

Your Answer

 
discard

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.