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

Add support for multiple aggregations #2682

Merged
merged 4 commits into from
Mar 29, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve check for numeric array keys
  • Loading branch information
felipeelia committed Mar 29, 2022
commit f3df048bfe711b830e4fa344b3d6332165b3e034
10 changes: 7 additions & 3 deletions includes/classes/Indexable/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1800,9 +1800,13 @@ public function format_args( $args, $wp_query ) {
/**
* Aggregations
*/
if ( isset( $args['aggs'] ) ) {
// An array of aggregations.
if ( isset( $args['aggs'][0] ) ) {
if ( ! empty( $args['aggs'] ) && is_array( $args['aggs'] ) ) {
// Check if the array indexes are all numeric.
$agg_keys = array_keys( $args['aggs'] );
$agg_num_keys = array_filter( $agg_keys, 'is_int' );
$has_only_num_keys = count( $agg_num_keys ) === count( $args['aggs'] );

if ( $has_only_num_keys ) {
foreach ( $args['aggs'] as $agg ) {
$formatted_args = $this->apply_aggregations( $formatted_args, $agg, $use_filters, $filter );
}
Expand Down