You can query a list of post IDs using $wpdb based on their slugs, and then use that in your filter. Here’s a simple example of how to do this:
function mm_search_filter( $query ) {
// We will query a list of post IDs
// by using $wpdb
global $wpdb;
$post_ids = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_name IN 'download-'");
// Now, pass the array of post IDs in
if (
! $query->is_admin &&
$query->is_search &&
$query->is_main_query() &&
! empty ( $post_ids )
) {
$query->set( 'post__not_in', $post_ids );
}
}
add_action( 'pre_get_posts', 'mm_search_filter' );
Related Posts:
- Create multiple Search functions for posts / custom post types and everything
- pre_get_posts and search query for admin
- Search function works improperly
- Force is_search to always TRUE
- How to conditionally pass a parameter to wordpress search to limit post types?
- why pre_get_posts works fine in post type archive, but not in search result list?
- Search for two strings in WP search
- Displaying number of search results for each post type
- Use pre_get_posts to display search results by meta in specific order
- Search custom posts by meta key in admin
- pre_get_posts improperly searching revisions
- WP search in metadata post
- meta field search too restrictive in pre_get_post() for custom search
- search filter for search and tag page doesn’t work
- How to search for (partial match) display names of WordPress users?
- How can i move search results onto a specific page?
- Unified search across separate WordPress installations
- How to insert a span inside a search form?
- Extending search query with additional $sentence value
- Search only blog posts (default WP search widget)
- Exclude pages from WordPress search result page
- Disable Redirect to Product Page on Search Results Page in WooCommerce [closed]
- Add custom field (value) to search result (without plugin)
- Combining Meta_Query key values for one array
- Search: Only One Result Returned
- How to redirect search result page to post
- Custom Permalinks Break Search Pagination
- Include Author profile in search results
- Adding arg to search results page
- search only pages if on page
- How to add WooCommerce SKU to search query?
- I’m trying to expand the scope of the default WP search algorithm. What am I doing wrong?
- How to return HTTP 404 when no search results found?
- Change query variable for wordpress search
- Search Results: Differentiate posts and pages
- How does WordPress know if a URL doesn’t exist?
- Highlight Search Results in Function.php
- How to make a search form?
- Change searched term
- Using ElasticSearch on WordPress
- How to restrict wordpress search to pages and disable products listing search?
- WordPress does not find author pages in search
- Search Everything & WP 3.7 update issues [closed]
- remove post edit.php search form and replace with my own
- Creating a Search Array From Multiple Tables
- Installing Solr for dedicated search
- custom wp_dropdown_categories items in wordpress
- How do I make search only search in post content?
- How can i preserve wordpress database encoding after using wp-cli search-replace with –export flag?
- Replace/Mute/Stop Search Query
- How to sort by columns within a search result without displaying all rows again after sorting
- How to add re-captcha to wordpress search?
- Where should I start looking if I want to implement my own custom search?
- Knowledge base high performance Live Search
- custom search results affected by _REQUEST set
- How to implement search suggestions into search bar?
- Limit search to a specific folder in website
- How do i append UNION SQL Query with default search query
- How to add one more query string with search query string
- Why is this search form not submitting when button is clicked?
- Search within table?
- Search by meta_query
- Restrict Search Results to Post Author
- Intelligent Search Filtering
- Include results with tags relevant to the search keyword with JSON rest API v2
- How to search titles/artist/album within a playlist, and only lists the results that match?
- Exclude posts with certain meta data from search results
- Custom search page wont allow URL params
- How to detect if the referer is 404 page?
- Included posts on a page searchable
- How to remove notice inside search.php when no results are found?
- Second page (and next) of search results redirects me to the home page
- Changing search terms results a 403 – dsIDXpress Pro plugin [closed]
- search: get minimum number of post for each post type
- WordPress Search function with partial and exact match
- make link to search page
- Search results thumbnails different size
- How to search in Elastic by post title/concerpt/content?
- how to disable autocomplete search on wpLink?
- Limit default Search query to post_title
- making a search form and search page in wordpress theme
- Some search results link to main page instead of post
- Enable query based wordpress search ?s=
- Adding custom search button to menu
- Use WordPress search in external static website
- How to show custom post type by either single meta_value or multiple meta_value(s) using WP_Query?
- Insert DIV container below 1st search result
- Extend search function with link to searched word
- Search for Author and Custom Post Type
- Search page isn’t returning any results
- how can I make the search return only single random correct result?
- How to display search query as formatted text?
- Adding attributes to the core search block form
- Wp admin: I need search meta key from table wp_usermeta in screen custom post type
- search videos on divi builder
- Search query alteration not working for meta values
- Search keyword store in custom meta key
- Pagination URL not good
- Customize search_filter($query) function
- Search with indexing and linking to PDF content