Skip to content
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

Add a filter to allow modifying the Autosuggest query #2908

Closed
JakePT opened this issue Jul 26, 2022 · 0 comments · Fixed by #2909
Closed

Add a filter to allow modifying the Autosuggest query #2908

JakePT opened this issue Jul 26, 2022 · 0 comments · Fixed by #2909
Assignees
Labels
enhancement module:autosuggest Issues related to the Autosuggest functionality
Milestone

Comments

@JakePT
Copy link
Contributor

JakePT commented Jul 26, 2022

Is your enhancement related to a problem? Please describe.
Currently there is no way to filter an Autosuggest query conditionally based on the input or form that triggered it, meaning that it's not possible for Autosuggest to reflect any additional fields in the form beyond a post_type field which is natively supported.

Describe the solution you'd like
We could add a 'filter', a la the epAutosuggestItemHTMLFilter filter for Autosuggest items, to allow modifying the JSON for the Elasticsearch query before it is sent. If this filter received the triggering input as a parameter then it could be used to modify the query as needed based on the search form.

Additionally, it might be worth examining the feasibility of implementing @wordpress/hooks for proper actions and filters, instead of a window property that can only be set once. The main consideration would be whether or not it is too large for regular front-end use.

Describe alternatives you've considered
The query template could be filtered by using pre_get_posts and checking if the s argument is set to the placeholder, but this would apply globally to all Autosuggest instances and would not be modifiable based on form values.

@JakePT JakePT added enhancement module:autosuggest Issues related to the Autosuggest functionality labels Jul 26, 2022
@felipeelia felipeelia added this to the 4.3.0 milestone Jul 26, 2022
@johnwatkins0 johnwatkins0 self-assigned this Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement module:autosuggest Issues related to the Autosuggest functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants