You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, so for some time now I have relied on wp's action pre_get_posts to customize logic before the query is run (I use it for things like: If two filters from the same cateogory are selected, the query between them is 'OR' and the other way around).
This worked on 3.4.0, but is now not working on 4.4.0.
Looking through changelogs and commits, I can see there's been a bit of a change in relation to how you guys work with tax_query, is there any summation of what has been changed in regards to this functionality, are there any caveats in the code I should know to get this working like it used to on 3.4.0, or do you guys have any suggestions beyond that?.
The result of $query->get('tax_query', []); on 3.4.0 gives me all the filters that have been applied among other things. Something like this:
Whereas on 4.4.0, I do not get any of this information anymore, other than the product_visibility information, it's always like this regardless of my search and filtering:
Hey @kastriotkastrati, that is a very interesting question. In fact, in ElasticPress 4.4.0 we've changed how we apply facets: filters are not applied to the WP Query anymore but to the ES query directly. That change was made (in #3045 and #3076) so we could apply OR filters between meta queries and tax queries, something not possible if using WP Query alone.
With that said, first of all, make sure you try to achieve the results you want by tweaking the "Match Type" setting in the Facets feature configuration. If that does not fully attend to your needs, you can use the ep_facet_query_filters filter with a priority higher than 10 to change how the taxonomy facet works by default.
To make things easier to understand, here is an outline of how the code flows:
A WP_Query is created
ElasticPress will translate that WP_Query into an Elasticsearch query. All filters are applied in the Post::parse_filters() method.
The Facets feature will add its own filter using the apply_facets_filters method.
That filter is built by calling the ep_facet_query_filters filter, so all facet types (meta and taxonomy at this point) can modify the ES query as needed. You will need to hook into that filter after those facet types already modified the filters to the applied (hence the priority greater than 10)
Hopefully, that helps you to adapt your code! Thanks
Hey @felipeelia. I appreciate your concise reply. The note on the priority of the filter was really really important and helpful. I was messing with multiple filters I found on the source code and in the end the final piece turned out to be the priority.
Describe your question
Hello, so for some time now I have relied on wp's action
pre_get_posts
to customize logic before the query is run (I use it for things like: If two filters from the same cateogory are selected, the query between them is 'OR' and the other way around).Hooking into this action, it will look like this:
This worked on 3.4.0, but is now not working on 4.4.0.
Looking through changelogs and commits, I can see there's been a bit of a change in relation to how you guys work with
tax_query
, is there any summation of what has been changed in regards to this functionality, are there any caveats in the code I should know to get this working like it used to on 3.4.0, or do you guys have any suggestions beyond that?.The result of
$query->get('tax_query', []);
on3.4.0
gives me all the filters that have been applied among other things. Something like this:Whereas on
4.4.0
, I do not get any of this information anymore, other than the product_visibility information, it's always like this regardless of my search and filtering:Any ideas what change between
3.4.0
and4.4.0
is the reason here?Code of Conduct
The text was updated successfully, but these errors were encountered: