Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
es-wp-query does currently not save taxonomy-queries, this ensures it…
Browse files Browse the repository at this point in the history
… does.

See: alleyinteractive#79
  • Loading branch information
gudmdharalds committed Apr 25, 2019
1 parent ac57b5e commit 25525f2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions class-es-wp-query-shoehorn.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,29 @@ function es_wp_query_shoehorn( &$query ) {
$es_query_args['fields'] = 'ids';
$es_query = new ES_WP_Query( $es_query_args );

/*
* If there were any taxonomies being queried,
* save those for later reconstruction.
*/

$taxonomies = get_taxonomies(
array(
'public' => true,
'_builtin' => false
),
'names',
'and'
);

$query_vars_taxonomy_save = array();

foreach( $taxonomies as $taxonomy_key => $taxonomy_name ) {
if ( isset($query->query_vars[ $taxonomy_key ] ) ) {
$query_vars_taxonomy_save[$taxonomy_key] =
$query->query_vars[ $taxonomy_key ];
}
}

// Make the post query use the post IDs from the ES results instead.
$query->parse_query(
array(
Expand All @@ -98,6 +121,14 @@ function es_wp_query_shoehorn( &$query ) {
$query->$key = $value;
}

/*
* Add taxonomies saved earlier.
*/

foreach( $query_vars_taxonomy_save as $tax_key => $tax_name ) {
$query->query_vars[ $tax_key ] = $tax_name;
}

new ES_WP_Query_Shoehorn( $query, $es_query, $query_args );
}
}
Expand Down

0 comments on commit 25525f2

Please sign in to comment.