Skip to content

Commit

Permalink
Make the global query query things again
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia authored and JakePT committed Mar 1, 2023
1 parent 61cbfe5 commit db7b2c2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
9 changes: 0 additions & 9 deletions includes/classes/Feature/Facets/Facets.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ public function set_agg_filters( $args, $query_args, $query ) {
add_filter( 'ep_post_filters', [ $this, 'remove_facets_filter' ], 11 );
}

/**
* This flag is used to differentiate filters being applied to the query and to its aggregations.
*/
$query_args['ep_facet_adding_agg_filters'] = true;

/**
* Filter WP query arguments that will be used to build the aggregations filter.
*
Expand Down Expand Up @@ -253,10 +248,6 @@ public function is_facetable( $query ) {
return true;
}

if ( $query->get( 'ep_is_facetable' ) ) {
return true;
}

if ( is_admin() || is_feed() ) {
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions includes/classes/Feature/Facets/Types/Meta/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public function render_block( $attributes ) {
public function render_block_preview( $request ) {
global $wp_query;

add_filter( 'ep_is_facetable', '__return_true' );

$search = Features::factory()->get_registered_feature( 'search' );

$attributes = $this->parse_attributes(
Expand All @@ -184,13 +186,11 @@ function ( $meta_fields ) use ( $attributes ) {
}
);

$wp_query = new \WP_Query(
[
'ep_is_facetable' => true,
'post_type' => $search->get_searchable_post_types(),
'per_page' => 1,
]
);
$args = [
'post_type' => $search->get_searchable_post_types(),
'posts_per_page' => 1,
];
$wp_query->query( $args );

/** This filter is documented in includes/classes/Feature/Facets/Types/Taxonomy/Block.php */
$renderer_class = apply_filters( 'ep_facet_renderer_class', __NAMESPACE__ . '\Renderer', 'meta', 'block', $attributes );
Expand Down
16 changes: 9 additions & 7 deletions includes/classes/Feature/Facets/Types/MetaRange/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public function render_block( $attributes ) {
* @return string
*/
public function render_block_preview( $request ) {
global $wp_query;

add_filter( 'ep_is_facetable', '__return_true' );

$search = \ElasticPress\Features::factory()->get_registered_feature( 'search' );
$facets = \ElasticPress\Features::factory()->get_registered_feature( 'facets' );

Expand All @@ -150,13 +154,11 @@ function ( $meta_fields ) use ( $facet ) {
}
);

$query = new \WP_Query(
[
'ep_is_facetable' => true,
'post_type' => $search->get_searchable_post_types(),
'per_page' => 1,
]
);
$args = [
'post_type' => $search->get_searchable_post_types(),
'posts_per_page' => 1,
];
$wp_query->query( $args );

$min_field_name = $facets->types['meta-range']->get_filter_name() . $facet . '_min';
$max_field_name = $facets->types['meta-range']->get_filter_name() . $facet . '_max';
Expand Down
14 changes: 7 additions & 7 deletions includes/classes/Feature/Facets/Types/Taxonomy/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ public function render_block( $attributes ) {
public function render_block_preview( $request ) {
global $wp_query;

add_filter( 'ep_is_facetable', '__return_true' );

$search = Features::factory()->get_registered_feature( 'search' );

$wp_query = new \WP_Query(
[
'ep_is_facetable' => true,
'post_type' => $search->get_searchable_post_types(),
'per_page' => 1,
]
);
$args = [
'post_type' => $search->get_searchable_post_types(),
'posts_per_page' => 1,
];
$wp_query->query( $args );

$attributes = $this->parse_attributes(
[
Expand Down

0 comments on commit db7b2c2

Please sign in to comment.