-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use WP_Query's search capability for core post fields #960
Conversation
81b2553
to
26e5b6a
Compare
Fixes issue where search queries would do exact string searches within title and content. WP core breaks up words in a search string and also searches the excerpt. Original issue still exists within taxonomy and meta fields. Fixes #894
26e5b6a
to
85ae79f
Compare
Hi jom, thanks for your solution. I am testing it right now and theres one problem left: So the think is, one of the words I am searching for has to be exact, otherwise the search finds nothing. Is there a way finding results without having one exact keyword? For instance: "prof for computer" Thanks a lot! |
@Bertsi Looking at WordPress core's code, that should produce results. Mind clearing your transients? I tried it with my environment: This is still limited by the restrictions of WordPress core's search capability. The "next level" of search is quite a big jump. In the future, I'm interested in looking at how we can improve compatibility with plugins that augment WordPress' search functionality (like FacetWP and SearchWP, which advertise WPJM compatibility). |
|
||
return $args; | ||
if ( ! empty( $search ) ) { | ||
$search = preg_replace( '/^ AND /', '', $search ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is clear what this preg replace is doing. I mean, I can guess, but it would be nice to know what the assumption of what the $search
variable has in it and why clearing out the AND keyword works here.
Is the assumption that $search
will always have just one clause in it at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WP Query starts its WHERE
query segment with 1=1
. The posts_search
filter prefaces its passed default value with AND
. I'm guessing they do this for more predictable chaining, but it still makes using the filter a bit clunky. Other hooked filters may have added other things after the default search query from WP core, but the assumption is that whatever is passed will start with AND
or will be an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I agree with your assessment that the next level of search is a huge jump that is beyond the scope of what core WordPress can really do, without specialized software like elastic search.
It looks good overall, just would like the one point of clarity with the mentioned search clause.
Holding pending @jchristopher's review for SearchWP. Hoping to get into core next week. |
Just took a pass through this PR, all good on my end 👍 Again, thank you so much for the proactive action letting me know about this upcoming change! |
Closes #894
Changes proposed in this Pull Request:
Addresses issue where search queries would do exact string searches within title and content. WP core breaks up words in a search string and also searches the excerpt. This PR uses this functionality in WP core for the core post fields. Original issue still exists within taxonomy and meta fields.
Testing instructions:
[jobs]
shortcode, search for "senior designer" and verify that "Senior UX Designer" appears.Proposed changelog entry for your changes:
Enhancement - Improves job filtering by breaking up search terms.