Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save any taxonomy-queries embedded in WP_Query objects #80

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
}
}
}
}