Selasa, 16 Mei 2017

02.08
By default, WordPress Search feature displays published posts and published pages in search results. Often when users are looking for something in a blog, it is most likely a post rather than a page. In this article, we will show you how to make your search more relevant and less crowded by excluding pages from WordPress search results.
First open your theme’s functions.php file and paste this code:
1function SearchFilter($query) {
2if ($query->is_search) {
3$query->set('post_type''post');
4}
5return $query;
6}
7 
8add_filter('pre_get_posts','SearchFilter');
Explanation: This code just searches for posts through setting the post_type. You can also make it do the opposite by setting the post_type to pages, so it only return pages in the search result.
Source: Bavotasan
If you want to exclude individual pages from WordPress search results, then use the plugin: Simply Exclude.

0 komentar:

Posting Komentar