Skip to content
Monitor live humans, bots, and datacenters Botcrawl Edge Try Edge Free
Search Engine Optimization

How To Exclude Individual Posts From WordPress Search Results

Exclude Or Hide Posts From WordPress Search Results

WordPressThere are many reasons to exclude or remove certain WordPress posts from being searched on your WordPress blog or website. You may have off topic posts which don’t relate to your dedicated blog topic or you may have written embarrassing rants you do not want to include in your search results query.

Luckily, using the exclude-posts function will override the standard WordPress search function and will allow you to exclude certain posts from being displayed in your WordPress website’s search results.

Down Copy and paste the code below into your functions.php file.
Change “Post ID here” to your individual post IDs, separated by commas (ie: 301, 2234, 281).
[Normal_Box]

function exclude_posts($query) {
    if ($query->is_search) {
       $query->set('cat','Post ID here');
  }
  return $query;
}
add_filter('pre_get_posts','exclude_posts');

[/Normal_Box]
[Note]Locating WordPress Page And Post IDs[/Note]

Sean Doyle

Sean is a tech author and security researcher with more than 20 years of experience in cybersecurity, privacy, malware analysis, analytics, and online marketing. He focuses on clear reporting, deep technical investigation, and practical guidance that helps readers stay safe in a fast-moving digital landscape. His work continues to appear in respected publications, including articles written for Private Internet Access. Through Botcrawl and his ongoing cybersecurity coverage, Sean provides trusted insights on data breaches, malware threats, and online safety for individuals and businesses worldwide.

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.