Article directory
- 1 WordPress site search excludes specified articles or pages
- 2 WordPress site search excludes certain categories of articles
- 3 WordPress site search excludes all pages
- 4 The Search Exclude plugin does not allow an article page to appear in the site's search results
- 5 WordPress site search does not display the specified article
Sometimes, we may not want a category, article or page to appear inWordPressSite search results.
So we can use filter (filter) to filter out certain articles or web pages.
- This is usingWordPress websiteThe advantages.
WordPress site search excludes specified articles or pages
// WordPress搜索结果排除指定文章或页面ID function wpsite_search_filter_id($query) { if ( !$query->is_admin && $query->is_search) { $query->set('post__not_in', array(40,819)); //文章或者页面的ID } return $query; } add_filter('pre_get_posts','wpsite_search_filter_id');
- Please note:The ID of the article or page on line 4 needs to be modified.
WordPress site search excludes certain categories of articles
// WordPress搜索结果排除某分类的文章 function wpsite_search_filter_category( $query) { if ( !$query->is_admin && $query->is_search) { $query->set('cat','-15,-57'); //分类的ID,前面的减号表示排除;如果直接写ID,则表示只在该分类ID中搜索 } return $query; } add_filter('pre_get_posts','wpsite_search_filter_category');
- Please note: Modify the ID and view the code comments.
WordPress site search excludes all pages
This is very practical, it is recommended to add ▼
// WordPress搜索结果排除所有页面 function search_filter_page($query) { if ($query->is_search) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','search_filter_page');
The Search Exclude plugin does not allow an article page to appear in the site's search results
- we useWordPress website, originally does not have the function of excluding a certain article page in the site search.
- However, by adding WordPress code, or installingWordPress pluginto achieve this function.
- The Search Exclude plugin allows you to exclude specific articles from your site's search results at any time.
After installing the Search Exclude plugin, you will see new features on the right side of the article editing interface ▼
Here's how to install a WordPress plugin ▼
WordPress site search does not display the specified article
As long as this "Exclude from Search Results" option is checked, the article will no longer appear in the site's on-site search results.
When you search in the WordPress front-end site, you will find that you cannot find excluded articles▼
In the management interface of the Search Exclude plugin, you can view all articles or pages that have been excluded from search on the site▼
- And, they can be removed in bulk.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How does WordPress exclude specified category/article pages from the site's search results? , to help you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-1057.html
Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!