This repository has been archived by the owner on Dec 17, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello -- I stumbled upon your plugin and fit the need for our website perfectly. The code is well organized and makes good use of filters and hooks to allow the plugin behavior to be further adjusted.
One thing we needed was the ability for the search function to also search the subtitle field (#37).
I tried a lot of different ways to achieve this; this pull request is what I finally came up with that achieved the desired behavior. However, I am not 100% certain that this implementation will not cause conflicts when other plugins or themes may attempt to further filter the search query, so it would be good if someone else can also look over this and do some testing to see if this implementation works safely.
My solution
The solution in this pull request uses the posts_clauses filter to directly modify the MySQL query clauses.
It performs regex matching to find the search term and create an additional WHERE clause.
The pros are:
The cons are:
Alternate method which did not work
I tried one other way to achieve this feature: Using the WP_Query Meta Query functionality would have been preferable because it would have made use of the built-in WP_Query object instead of modifying SQL directly. For example:
This unfortunately does not work because in a search query, the results are still filtered down to only posts which have the
user_search_term
present in either thepost_title
orpost_content
fields.From searching online, others were able to implement this type of functionality by performing two queries and combining the results: 1) to search only the title and content fields, and 2) to search only the meta fields.