Exclude Posts From WordPress Search
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]

WordPress Bot Protection

Bot Blocker for WordPress

Monitor bot traffic, review live activity, and control AI crawlers, scrapers, scanners, spam bots, and fake trusted bots from one clean WordPress dashboard.

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.

View all posts →

2 Comments

  1. Leigh

    Same here, not having any luck this seems to break the search completely. Would be great to have a solution for this!

  2. AndyiBM

    Hi Sean – tried this, but all it succeeds in doing is breaking the search altogether, so no pages appear for any search term.

Leave a Comment

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