I've messed up the admin search functionality. Help!
-
This all started because, on the front-end, I wanted the search query to include terms from taxonomies and custom meta. So, after a google, I found the following code which I added to my functions file:
add_filter('posts_where', 'advanced_search_query' ); function advanced_search_query( $where ) { if( is_search() ) { global $wpdb; $query = get_search_query(); $query = like_escape( $query ); // include postmeta in search $where .=" OR {$wpdb->posts}.ID IN (SELECT {$wpdb->postmeta}.post_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->postmeta}.meta_key = 'bible_reference' AND {$wpdb->postmeta}.meta_value LIKE '%$query%' AND {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)"; // include taxonomy in search $where .=" OR {$wpdb->posts}.ID IN (SELECT {$wpdb->posts}.ID FROM {$wpdb->posts},{$wpdb->term_relationships},{$wpdb->terms} WHERE {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id AND {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->terms}.term_id AND {$wpdb->terms}.name LIKE '%$query%')"; if(WP_DEBUG)var_dump($where); } return $where; }
It worked a treat for my front-end search. However, I’ve since discovered that the admin search has now gone to pot. For example, if I search in the list of pages in the dashboard, it only displays results from my custom post types. And, if I try searching again, once the first lot of results is displayed, I receive an error: ‘Invalid post type’.
I’ve tried removing the filter using remove_filter() but nothing seems to work.
Please can someone help?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘I've messed up the admin search functionality. Help!’ is closed to new replies.