solutionweb

WordPress Common Errors and Solutions

WordPress search results only show article types, blocked pages, attachment pages, versions, etc.

In fact, there are other types of search results, such as single page, revised version and so on. Obviously, these are not what I want. In fact, it is enough to just show the article page to the user.

On the code:

//Search results only show article types.
function search_filter_page($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’);
}
return $query;
}
add_filter(‘pre_get_posts’,’search_filter_page’);
In this way, only articles with post type will appear in our search results.

Back to top