Approaching this from the SQL is a mistake, and instead a quick search of the official dev docs for filename reveals a filter named wp_allow_query_attachment_by_filename
that is set to true by default:
https://developer.wordpress.org/reference/hooks/wp_allow_query_attachment_by_filename/
apply_filters( 'wp_allow_query_attachment_by_filename', bool $allow_query_attachment_by_filename )
Filters whether an attachment query should include filenames or not.
This means you can disable querying filenames with a quick filter like this:
add_filter( 'wp_allow_query_attachment_by_filename', '__return_false' );
Where __return_false
is a function built into WordPress to save time writing filters like this.
Related Posts:
- Can I force WP_Query to return no results?
- Post_count only shows the number of results per page
- WP Query where title begins with a specific letter
- Search custom taxonomy term by name
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Tracing the life of a query
- Want to redirect if search query match exact title of any post
- Ignore a filter on the media library
- Pagination not working for Custom search form & custom result template
- How to support multiple search terms query within one process?
- Pagination broken when merging search results with additional WP_Query
- Custom search form with empty parameters
- How to search by title or tags exclusively?
- WordPress search exact match
- Pagination wont work with search results template [duplicate]
- How do I search WordPress by different fields without a plugin?
- Multiple keyword search
- Using next/previous_posts_link with customised search
- WordPress custom search form with pre_get_posts not work
- Search – Ajax – Alter Query Parameters with Pagination
- Add custom search results to main WP search [duplicate]
- Multiple search queries on one page
- tax_query shows no results if nothing is selected
- Searching through different categories on different pages code is not working
- WP Query search for attachments and their exact title
- WP_Query’s “request” SQL Query
- Including only current user’s posts in search
- Show selected images on top in Media Manager
- is_search was called incorrectly
- How do I search inside specific taxonomies in WordPress
- Modifying the Search Results
- Custom category search box for WordPress
- Refine search results using WP_Query
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Search Posts with Custom Fields as query
- get all images from the wordpress media library with link to the post they are associated with
- My combination of ‘post_type’ and ‘tax_query’ not working?
- How to prevent WP_Query from filtering on ‘s’ but keep ‘s’ for other purposes?
- Block internal search queries with pre_get_posts and regex rules
- Add dynamic search to paginated WP_Query
- How to make the WP query search for the “s” arg in other places too
- Search Exact on WordPress – Relevannsi Solution Not Working
- Excluding posts from search results page with meta query not working
- Pagination repeating posts on search results
- I have problems with the search query using multiple post types
- WP_Query no result if keyword contains number
- Multiple WP_Query args combinations according to post type
- Categories In English version showing not canonical URL, instead shows query search result
- Filter admin ajax data by url query
- How to extend WP_query to a specific table?
- Display the search results like the original pages
- How to use jQuery validation to set the search bar to accept only a specific input?
- Display Search Results by tag_ID in my search.php
- How to debug none working search query?
- getting posts by tags
- Add to search posts query array with post IDS which will appear first
- Custom Post Type WP_Query with filters and search
- Search with WP_Query, but ignore href URLs in anchor tags?
- WordPress search page pagination displaying but not functional
- Search has query that will return no results
- WP Query – Search in title or author_name
- Limit default Search query to post_title
- Get posts by similar names and categories
- Logging search queries for logged-in users
- How to show terms from another taxonomy
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Order & Orderby clause not working with custom query
- How can I modify standard search query to include also ACF custom fields values?
- A very strange problem with search query
- Search format not matching taxonomy query
- How to make the default WordPress search return borader results
- Search Functionality broken by the wp 4.2 update
- WordPress WP_Query offset parameter not working with search parameter
- Custom search (wp query by custom fields)
- WordPress WP_Query Array Custom search via taxonomies
- Custom Search Query – include only custom fields and title
- $wp_query when new WP_Query
- Need help setting up a search form for wordpress [duplicate]
- Search Query that Includes Custom Table
- Manipulating a query
- Custom search: Search posts but display parent page in results
- Query posts by custom fields
- Searching in specific custom post type
- Search (Custom Form, Custom Search Result)
- WP Query Obj: Set value to be unequal | Hide media by admin
- Help with showing text when something is entered in my search bar
- Why does WP_Query not search for two ‘meta_query’ keys separated with OR?
- Filtering product search results using tags
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- How does Show Posts based on a keyword search work in WP_Query
- Search query alteration not working for meta values
- Search results stuck on page 1
- Custom Taxonomy in custom REST API search
- Advanced Search – Is this possible?
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge
- Modify WordPress Search
- Rewrite URL custom search query