Hello
I’d like to know how can i remove the question and answer from the search results of my wordpress ?
Thanks
Hi,
You can add the following code to the functions.php
file to make WordPress search only works with posts, pages:
function wpshock_search_filter( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array('post','page') );
}
return $query;
}
add_filter('pre_get_posts','wpshock_search_filter');
Hope this helps !
Great! You are the best!
In order to search only post I need to delete ‘page’ in array?
Thank you! You are the best!
Dominic, can you please me search only post without page?
Does this code affect only WP standard search?
I would like standard WP search should find post and search on your plugins page should find only questions.
thanks
You can try the following code:
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
Hope this helps !
Great!
Still plugins search finds all posts too but I think this is a minor bug which will be resolved in the next release.
Please login or Register to submit your answer