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
When querying using WP_Query() with Elasticsupport enabled, es-wp-query can cause WP_Query objects to drop taxonomy queries attached. This can cause get_query_var('taxonomy') to return an empty string.
For instance, when the main loop calls WP_Query() with a custom taxonomy, like this:
then subsequent calls to get_query_var( 'taxonomy' ) will return an empty string. This will not happen with no es argument passed to WP_Query(), as then get_query_var( 'taxonomy') will return the correct value.
Cause
This problem likely occurs because in the function WP_Query::get_posts() the term and other keys of WP_Query::$query_vars are added after the pre_get_posts action hook is called here -- this action hook is used to take over any calls to WP_Query() or get_posts() and offload the query to Elasticsearch. The term key (and others) are added in WP_Query::get_posts() around here.
The action hook implemented by class-es-wp-query-shoehorn.php (es_wp_query_shoehorn) will call WP_Query::parse_query()here, and because it does not add back in terms and taxonomy information after re-parsing, the terms and taxonomy information will be left out -- this will ultimately impact the following:
if ( ! empty( $this->tax_query->queried_terms ) ) {
found in class-wp-query.php (here) as with Elasticsearch enabled, it is evaluated as false and evaluated as true otherwise. It is after this point term and other values are added to WP_Query::$query_vars.
Solution
The solution appears to add the taxonomy information back in after calling WP_Query::parse_query(), which will ensure the terms being available by get_query_var().
The text was updated successfully, but these errors were encountered:
Description
When querying using
WP_Query()
with Elasticsupport enabled,es-wp-query
can causeWP_Query
objects to drop taxonomy queries attached. This can causeget_query_var('taxonomy')
to return an empty string.For instance, when the main loop calls
WP_Query()
with a custom taxonomy, like this:then subsequent calls to
get_query_var( 'taxonomy' )
will return an empty string. This will not happen with noes
argument passed toWP_Query()
, as thenget_query_var( 'taxonomy')
will return the correct value.Cause
This problem likely occurs because in the function
WP_Query::get_posts()
the term and other keys ofWP_Query::$query_vars
are added after thepre_get_posts
action hook is called here -- this action hook is used to take over any calls toWP_Query()
orget_posts()
and offload the query to Elasticsearch. The term key (and others) are added in WP_Query::get_posts() around here.The action hook implemented by
class-es-wp-query-shoehorn.php
(es_wp_query_shoehorn
) will callWP_Query::parse_query()
here, and because it does not add back in terms and taxonomy information after re-parsing, the terms and taxonomy information will be left out -- this will ultimately impact the following:found in
class-wp-query.php
(here) as with Elasticsearch enabled, it is evaluated asfalse
and evaluated astrue
otherwise. It is after this point term and other values are added toWP_Query::$query_vars
.Solution
The solution appears to add the taxonomy information back in after calling
WP_Query::parse_query()
, which will ensure the terms being available byget_query_var()
.The text was updated successfully, but these errors were encountered: