Created
July 10, 2014 09:24
-
-
Save ideag/2987f4e6df96758d4991 to your computer and use it in GitHub Desktop.
Filter post_meta in WordPress searches
This file contains hidden or 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
| <?php | |
| add_filter('pre_get_posts','klausk_search_meta'); | |
| function klausk_search_meta($q=false){ | |
| if (!is_admin() && $q->is_main_query() && $q->is_search()) { | |
| $meta_query = array( | |
| array( | |
| 'key' => 'klausk_answer', | |
| 'value' => like_escape($q->get('s')), | |
| 'compare' => 'LIKE', | |
| ), | |
| ); | |
| $q->set('meta_query',$meta_query); | |
| } | |
| return $q; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment