I have a curious problem with the Wordpress search engine of my website (the one that makes URLs as +word
). When I installed Wordpress I noticed that when I used the search engine of my website, the results was only posts... it was as if the pages did not exist. Anyway, I don't know if that is normal for Wordpress blogs. After months, I was searching a word and I noticed that in the results the pages appeared! This amazing situation has continued for a lot of time but, from last week, inexplicably, pages don't appear in the results again.
I told you the whole story to be clear, but my question is only one: How can I solve this strange behavior of my Wordpress search engine? For me it's very important that my users can also find pages.
I have a curious problem with the Wordpress search engine of my website (the one that makes URLs as http://sitename?s=searched+word
). When I installed Wordpress I noticed that when I used the search engine of my website, the results was only posts... it was as if the pages did not exist. Anyway, I don't know if that is normal for Wordpress blogs. After months, I was searching a word and I noticed that in the results the pages appeared! This amazing situation has continued for a lot of time but, from last week, inexplicably, pages don't appear in the results again.
I told you the whole story to be clear, but my question is only one: How can I solve this strange behavior of my Wordpress search engine? For me it's very important that my users can also find pages.
Share Improve this question asked Oct 1, 2019 at 16:02 NintendomiNintendomi 53 bronze badges1 Answer
Reset to default -1WordPress search results can depend on your theme or plugins as well. Try enabling the default theme called Twenty Ninteen and then try your search.
The default behavior is to search both, posts and pages. However if your theme is changing that you can force the search of pages.
In order to search only pages in WordPress, we will need to add a PHP filter to the WordPress functions file. Open your functions.php file then copy and paste the code below. Your WordPress site will now return pages and posts in the search results.
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'page'));
}
return $query;
}
add_filter('pre_get_posts', 'SearchFilter');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745110885a4611843.html
评论列表(0条)