Support more search form fields in Instant Results #2978
Labels
enhancement
front end
Issues mostly related to the Front End like JavaScript/React and CSS.
low priority
module:instant-results
Issues related to the Instant Results functionality
Milestone
Is your enhancement related to a problem? Please describe.
Currently the Instant Results modal is opened by submitting a form containing a search input. This opens the modal and sets the search term in Instant Results. Additionally, if any fields with the name
post_type
are found, this will be used to apply a post type filter in Instant Results.The problem is that these are the only two fields supported, so if a form has a category dropdown or sorting option, any selections in those fields would not be reflected in Instant Results.
Describe the solution you'd like
At the moment we manually check for those two fields and set them as search arguments when the modal is opened. We could support any field that uses the name of our parameters by converting the form data to URL parameters and passing those through the existing
getArgsFromUrlParams()
function that's used for history navigation.This would enable support for setting more search parameters from a search form, but Instant Results doesn't always use the same parameter names that pre-existing search forms might. For example, a default
wp_dropdown_categories()
will use the namecat
, but Instant Results expects the parametertax-category
for filtering by category.So if we want to support Instant Results for existing search forms not built with Instant Results in mind, or even future changes to the search block as outlined on WordPress/gutenberg#40585, we will need to map WordPress query vars to our parameter names.
Additional context
Related to #2507.
The text was updated successfully, but these errors were encountered: