Skip to content

feat/3954: Add filters to exclude post types and taxonomy terms from Instant Results - #4290

Merged
felipeelia merged 18 commits into
developfrom
feat/3954
Aug 17, 2026
Merged

feat/3954: Add filters to exclude post types and taxonomy terms from Instant Results#4290
felipeelia merged 18 commits into
developfrom
feat/3954

Conversation

@Sidsector9

@Sidsector9 Sidsector9 commented Feb 22, 2026

Copy link
Copy Markdown
Member

Description of the Change

  • Adds ep_instant_results_excluded_post_types filter to exclude post types and related posts from Instant Results.
  • Adds ep_instant_results_excluded_term_ids filter to exclude taxonomy terms from Instant Results facets.

Post Type Exclusion (ep_instant_results_excluded_post_types)

Excluded post types are removed from both the Post Type facet and the search template itself. This means content of that type will not appear in Instant Results at all.

The search template is regenerated when Instant Results settings are saved, when the weighting configuration is saved, and after a full sync. So after changing this filter, save either settings screen, run a sync, or run wp elasticpress put-search-template, otherwise the old template stays in use.

add_filter( 'ep_instant_results_excluded_post_types', function( $excluded ) {
    $excluded[] = 'page';
    return $excluded;
} );

Term Exclusion (ep_instant_results_excluded_term_ids)

Excluded terms are hidden from every taxonomy facet (Category, Tag, etc.) but posts associated with those terms still appear in search results. This is intentional, a post can belong to multiple terms, so excluding a term from the facet should not remove posts that also match through other, non-excluded terms.

add_filter( 'ep_instant_results_excluded_term_ids', function( $excluded ) {
    $excluded[] = 1; // Uncategorized
    return $excluded;
} );

Closes #3954

Changelog Entry

Added: ep_instant_results_excluded_post_types filter to exclude post types from Instant Results facets and search results.
Added: ep_instant_results_excluded_term_ids filter to exclude taxonomy terms from Instant Results facets.

Credits

Props @feliciaoctocog, @Sidsector9

Checklist:

@Sidsector9 Sidsector9 self-assigned this Feb 23, 2026
@Sidsector9 Sidsector9 added this to the 5.4.0 milestone Feb 23, 2026
@felipeelia

Copy link
Copy Markdown
Member

We will need tests for this one, @Sidsector9.

@Sidsector9

Copy link
Copy Markdown
Member Author

@felipeelia the tests have been added 👍

@Sidsector9 Sidsector9 modified the milestones: 5.4.0, 5.3.4 Jul 27, 2026

@felipeelia felipeelia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sidsector9 We will need to replace all the 5.4.0 with 5.3.4. In addition to that, can you please change get_excluded_post_types and get_excluded_term_ids returns, so we always make sure they are sending the correct types back to the caller?

Something like array_filter( array_map( 'absint', (array) apply_filters( 'ep_instant_results_excluded_term_ids', [] ) ) );, but properly written.

@felipeelia
felipeelia merged commit 14f7023 into develop Aug 17, 2026
55 of 70 checks passed
@felipeelia
felipeelia deleted the feat/3954 branch August 17, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Filters from Instant Results

2 participants