This trick uses pre_get_posts filter to remove pages from the query results. Here is the code:
1 2 3 4 5 6 7 8 | // Remove pages from search results function shailan_remove_pages( $query ){ if ( $query ->is_search){ $query ->set( 'post_type' , 'post' ); } return $query ; } add_filter( 'pre_get_posts' , 'shailan_remove_pages' ); |
Open your
functions.php
file and put this snippet in. Save and upload.After the edit is done, you can test it out by searching a page title.
This way you can make sure no pages are listed on your search results page.
Hope you like this trick. Enjoy!
Comments
Post a Comment