To specifically exclude posts with “2024” in their titles using a code snippet, you can add this to your theme’s functions.php
file:
function exclude_title_posts( $query ) {
if ( $query->is_search && !is_admin() ) {
$query->set('post_title_not_like', '2024');
}
}
function modify_search_where( $where, $query ) {
global $wpdb;
if ( $title_not_like = $query->get( 'post_title_not_like' ) ) {
$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title NOT LIKE %s ", '%' . $wpdb->esc_like( $title_not_like ) . '%' );
}
return $where;
}
add_filter( 'posts_where', 'modify_search_where', 10, 2 );
add_action( 'pre_get_posts', 'exclude_title_posts' );
This snippet modifies the WordPress query when it’s a search query, adding a condition to exclude posts whose titles contain “2024”.
Related Posts:
- Search results URL without query string variables
- Use “search” in permalink?
- Site Title in my Search URL
- Enhancin 404 to contain a search from URL
- Removing &submit=Search from search parameters?
- Change output URL Search module
- “feed” added at the end of my URLs
- 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
- How to check if feed URL was requested?
- 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?
- template_include for search.php makes WordPress think its on the home page
- can’t limit search to only pages
- Include custom table into search results
- How to exclude post body from WP search
- 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 avoid the specific page while searching in WordPress without plugin?
- Best way to Integrate Google Search?
- How to add additional search terms (e.g. synonyms) to the search?
- Combine internal search with Google custom search?
- Comparing between a negative and positive number
- Any reason why search result lists only one entry?
- Display just child pages of a certain page in search results
- How to make wordpress default search to woocommerce search
- pre_get_posts action: Search by post_title and post_content with different search phrase in the same query
- Why won’t is_search work inside functions.php?
- Search by keywords with boolean operators
- Search functionality – include date, category and author search
- Redirect All Search Links Containing – to + on WordPress
- WordPress Search matching hyphenated words
- How to stop WordPress Search form from searching only in current page?
- WordPress custom search url
- How can I make a search form that can search taxonomies and posts?
- How can I include author (their archive page) in search results?
- How to search media library alt text and title fields
- how to create search and filter form generating “plus” symbols in url in between category names?
- Meta query: How do I return posts within a date period from a given month?
- Creating a Searchable PDF Archive of Publications
- Display post titles that match string in post content
- Search – Only search for post meta field
- Search Form Based On Tutorial Not Working
- how to show Author information in search results
- Sitelinks Search box schema confusion
- Search for anything in site
- Display Search Results after search 1st link
- Make archive page show up in search results?
- How can I add search box in single.php?
- Exclude image url from search query
- WordPress custom search by post type
- WP_User_Query not searching
- Only display post content in search results
- meta post search
- “Revision” records in wp_posts have original post type instead of “revision”
- Search engine for WP as CMS [closed]
- Why does this search.php not work?
- Breadcrumbs: Search result not displayed when static page is on top
- Can’t place two custom post types into the WordPress search query?
- Replacement search plugin that reads widgets or catalogs entire page?
- Rewrite wp function
- WordPress custom search only works from some pages
- WordPress search – Display the paragraph which has the searched word/term
- How to Fix Form elements do not have associated labels in WordPress Search Form (without button)
- Search to include external content
- pulling in external JSON search results into WordPress
- How to Integrate Live search in WordPress?
- How to create a custom filter in WordPress?
- search results in custom template search.php
- Search results are showing full page instead of sample
- how to change custom post type search template to output search results in posttype-archive.php
- Search: display all found matches inside post
- Search For Custom Post Type and Custom Fields
- WordPress search.php pulling search results but also matching a page and pulling that information in
- Searching on my blog is not working
- Search Results Customization
- Search.php Modification Needed
- Search taxonomy terms, not posts
- “Modular/reusable” content and search results
- I want to edit the search function
- Search doesn’t work with ‘relation’ => ‘OR’
- Add meta tag to search results
- Searchform for searching specific categories
- How to display articles based on composed tag
- Selectbox and Searchform and Custom Search Page
- Hightlight search-terms with functions does remove or disable other filters?
- Change the text “search result for” on search result page
- Search query with quotes
- Search redirects to index
- Search Results with googlemaps
- Want to creat a search for my wordpress theme [closed]
- Making ACF fields appear in search results
- How to make wordpress Dynamic Search-icon from Predesigned Static Html Search-icon?
- search ALSO by POST-ID with a public front-end search box
- how to create a multi selector dropdown search box by code?