| @@ -70,10 +70,8 @@ | ||
| 70 | 70 | */ |
| 71 | 71 | public function get_meta_range( \WP_REST_Request $request ) { |
| 72 | 72 | global $wp_query; |
| 73 | 73 | |
| 74 | - add_filter( 'ep_is_facetable', '__return_true' ); | |
| 75 | - | |
| 76 | 74 | $search = Features::factory()->get_registered_feature( 'search' ); |
| 77 | 75 | $facets = Features::factory()->get_registered_feature( 'facets' ); |
| 78 | 76 | |
| 79 | 77 | $facet = $request->get_param( 'facet' ); |
| @@ -87,10 +85,11 @@ | ||
| 87 | 85 | } |
| 88 | 86 | ); |
| 89 | 87 | |
| 90 | 88 | $args = [ |
| 91 | - 'post_type' => $search->get_searchable_post_types(), | |
| 92 | - 'posts_per_page' => 1, | |
| 89 | + 'post_type' => $search->get_searchable_post_types(), | |
| 90 | + 'posts_per_page' => 1, | |
| 91 | + 'ep_is_facetable' => true, | |
| 93 | 92 | ]; |
| 94 | 93 | $wp_query->query( $args ); |
| 95 | 94 | |
| 96 | 95 | $min_field_name = $facets->types['meta-range']->get_filter_name() . $facet . '_min'; |
| @@ -95,15 +94,17 @@ | ||
| 95 | 94 | |
| 96 | 95 | $min_field_name = $facets->types['meta-range']->get_filter_name() . $facet . '_min'; |
| 97 | 96 | $max_field_name = $facets->types['meta-range']->get_filter_name() . $facet . '_max'; |
| 98 | 97 | |
| 99 | - if ( empty( $GLOBALS['ep_facet_aggs'][ $min_field_name ] ) || empty( $GLOBALS['ep_facet_aggs'][ $max_field_name ] ) ) { | |
| 98 | + $aggregations = $facets->get_query_aggregations( $wp_query ); | |
| 99 | + | |
| 100 | + if ( empty( $aggregations[ $min_field_name ] ) || empty( $aggregations[ $max_field_name ] ) ) { | |
| 100 | 101 | wp_send_json_error(); |
| 101 | 102 | return; |
| 102 | 103 | } |
| 103 | 104 | |
| 104 | - $min = $GLOBALS['ep_facet_aggs'][ $min_field_name ]; | |
| 105 | - $max = $GLOBALS['ep_facet_aggs'][ $max_field_name ]; | |
| 105 | + $min = $aggregations[ $min_field_name ]; | |
| 106 | + $max = $aggregations[ $max_field_name ]; | |
| 106 | 107 | |
| 107 | 108 | wp_send_json_success( |
| 108 | 109 | [ |
| 109 | 110 | 'min' => $min, |