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 fix taxonomy-queries, this patch will …
Browse files Browse the repository at this point in the history
…do so.

See alleyinteractive#79.
  • Loading branch information
gudmdharalds committed Apr 25, 2019
1 parent 574ff9c commit cdf75b4
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion class-es-wp-query-shoehorn.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ function es_wp_query_shoehorn( &$query ) {
$es_query_vars['fields'] = 'ids';
$es_query = new ES_WP_Query( $es_query_vars );

/*
* 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 ];
}
}

$query->parse_query( array(
'post_type' => 'any',
'post_status' => 'any',
Expand All @@ -73,6 +96,15 @@ function es_wp_query_shoehorn( &$query ) {
foreach ( $conditionals as $key => $value ) {
$query->$key = $value;
}

/*
* Add taxonomies saved earlier.
*/

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

$shoehorn = new ES_WP_Query_Shoehorn( $query, $es_query, $query_args );
}
}
Expand Down Expand Up @@ -219,4 +251,4 @@ private function reboot_query_vars( &$query ) {
$q['posts_per_page'] = get_option( 'posts_per_page' );
}
}
}
}

0 comments on commit cdf75b4

Please sign in to comment.