What you want to do is use the pre_get_posts
action to exclude the post ID from the search results query. This allows you to “pre” set some elements of the query, including an array of post IDs to exclude with the “post__not_in” value.
Suppose the ID of your privacy policy it 11, then you’d pass 11 in the post__not_in
array along with any other IDs you are excluding.
add_action( 'pre_get_posts', 'my_search_exclude' );
function my_search_exclude( $query ) {
if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'page', 'product' ) );
$query->set( 'post__not_in', array( 11 ) );
}
}
Related Posts:
- How can I implement a location based (zip code) search in WordPress?
- How to highlight search terms without plugin
- Remove meta robots tag from wp_head
- Template issues getting ajax search results
- Complex Search functionality. Advice needed
- How to use next_post_link and previous_post_link on single posts in search results
- Why is there a class=”screen-reader-text” on my search button?
- can’t limit search to only pages
- Include custom table into search results
- How to exclude post body from WP search
- ElasticPress Indexing multiple sites
- Search outside of the “loop”
- Replace URL with Site Title in Search Results
- Force WP to use a certain search template
- Do not allow to search certain words
- Display title for search engine visitors
- How to show a random selection of posts from the search
- Related Tags Concept
- Default WP search excluding specific characters, is it possible?
- Comparing between a negative and positive number
- Searching by meta values showing inappropriate result
- Search by keywords with boolean operators
- Remove WHERE conditions from search query
- Redirect All Search Links Containing – to + on WordPress
- How to make wordpress Dynamic Search-Bar from Predesigned Static Html Search-Bar?
- Change Search url slug for each site in a multisite network
- URL search link for ‘category__and’ instead of php query
- Search media by title and description – Frontend
- Is there a way to add a custom text + link above search results for different searches?
- How to change tab’s title in search results pages? [closed]
- Customise Excerpt start and end
- Generate list of tags from search results
- Template issues getting ajax search results
- How can I implement Search feature for Membership site?
- WordPress search with quotations returning to homepage
- Search queries don’t seem to work?
- How to display search results in search.php
- Array_search ignoring the first element [closed]
- Search WooCommerce Products in WordPress
- Order search results by category
- Strip HTML Tags From Search Results
- Should I create a parent page with no content? [closed]
- some one help . search not jump to search page
- Why should we use the name attribute with the value “s” in the creation of the search form?
- The Search FoRM Dilemma || The Search form Templating
- Search for anything in site
- How can I add search box in single.php?
- adding more text to a query string
- Independent search tool that returns exact match of a post title
- Connecting Google Site Search with WordPress Taxonomies/Categories/Tags
- Search using WP_Query
- Only display post content in search results
- My search form finds page 1 results but shows “error 404 page not found” on pages 2 on or clicking next
- meta post search
- search page not found? (search.php or searchpage.php)
- Media Library / Backend: How can I search for text in the ALT Text field?
- Rewrite wp function
- Search custom posts by meta key in admin
- How to fetch Email addres of an author via ID?
- How to Fix Form elements do not have associated labels in WordPress Search Form (without button)
- Search within the current page
- How to exclude specific post_type from default search?
- Search issue on special Character
- Modify main search form to search user too
- Editing a Search Form
- Removing &submit=Search from search parameters?
- how to prevent the spam on search function?
- customize search result in wordpress
- Highlight search words in excerpt
- $_GET value is losing it’s space
- limit the number of searches
- Search For Custom Post Type and Custom Fields
- How can I prevent the Search Results Page from changing title?
- Custom search page and url in multilanguage
- Searching on my blog is not working
- WP search in metadata post
- “Modular/reusable” content and search results
- Make the title and […] clickable in result search
- Add Search Form to Dropdown menu
- Search doesn’t work with ‘relation’ => ‘OR’
- Add meta tag to search results
- Searchform for searching specific categories
- Selectbox and Searchform and Custom Search Page
- Hightlight search-terms with functions does remove or disable other filters?
- wp_redirect and search engine bots
- SQL: Search query to get attachments only of those parents which are published
- Change the text “search result for” on search result page
- Search redirects to index
- Want to creat a search for my wordpress theme [closed]
- Return 404 for /search/ queries – For Genesis
- Deprecating WordPress URL from Google, promoting custom domain [closed]
- Search with multiple selects that include tags
- Search results from a specific database table
- Exclude category in search results in functions.php
- Search results truncated
- “feed” added at the end of my URLs
- Disable – Post search field – for non-admin roles in WP dashboard
- Search results heading and counter not working – Oxygen Builder
- How to quickly search posts by title in Admin interface
- Blocking spambots from Search form