CMS Scripts

Exclude pages from search results in WordPress

Exclude pages from search results  in WordPress

The research shows the results, including WordPress pages. A quick way to solve this problem is to remove all pages from the search results. The function can be expanded with the addition of other types of post_type for the query. File to edit: functions.php

 

PHP
1
2
3
4
5
6
7
function filter_search($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘page’);
}
return $query;
}
add_filter(‘pre_get_posts’, ‘filter_search’);

About the author

Hamid Awan

Hamid Awan is a computer Geek, Internet Entrepreneur, Business Guy, Blogger and Digital Marketing Specialist. He also helps companies to grow their Online Business. At Tech Entires he writes about Money Making Ideas, Business, Android Apps, Blogging, WordPress, SEO, Technology and Computer Tips and Tricks. If you have any suggestion, you can contact us through our Contact Us Page

Leave a Comment