Skip to content

BUG: Allow explicit disabling of faceting via ep_is_facetable query argument #4335

Description

@dmitrijCraq

Describe the bug

I’m currently implementing a custom search page using ElasticPress by overriding search.php. In this setup, I rely on WP_Query with ep_integrate = true to keep ElasticPress fully active for search results.

However, when the “facets” feature is enabled in the ElasticPress settings, the plugin automatically adds aggregations (faceting) to the query. In my case, I need ElasticPress enabled, but I explicitly want to disable faceting for specific queries.

Problem

Looking at the implementation of is_facetable(), the logic for the ep_is_facetable query argument is effectively treated as a positive-only override:

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

This means that only truthy values are considered, while false is ignored and falls through the rest of the logic.

Because of this behavior, it would be useful and more consistent to explicitly handle the case where ep_is_facetable is set to false, so that faceting can be disabled at query level in a deterministic way.

In particular, a condition such as:

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

Steps to Reproduce

Insert the following code in functions.php and enable the Filter feature from the plugin settings.

add_action( 'pre_get_posts', 'qtheme_child_ep_main_search_query_args', 9 );

function qtheme_child_ep_main_search_query_args( WP_Query $query ): void {
	if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
		$query->set( 'ep_is_facetable', false );
	}
}

In Facets.php line 252 inspect the is_facetable method. If ep_is_facetable is false the function still returns true.

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress and ElasticPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions