Created
June 7, 2012 15:47
-
-
Save not-only-code/2889579 to your computer and use it in GitHub Desktop.
adds meta query on Wordpress search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* adds meta values on search query | |
* | |
* @param object $query | |
* | |
**/ | |
function custom_search_query( $query ) { | |
if ( !is_admin() && $query->is_search ) { | |
$query->set('meta_query', array( | |
array( | |
'key' => '__meta_key__', | |
'value' => $query->query_vars['s'], | |
'compare' => 'LIKE' | |
) | |
)); | |
// you can add additional params like a specific 'post_type' | |
// $query->set('post_type', 'project'); | |
}; | |
} | |
add_filter( 'pre_get_posts', 'custom_search_query'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment