Skip to content

Conversation

@laraib15
Copy link

@laraib15 laraib15 commented Jan 1, 2026

Description of the Change

This PR prevents a fatal error in Instant Results taxonomy facets when the ep_facet_include_taxonomies filter returns unexpected values (e.g., a taxonomy slug string such as internal_tags rather than a WP_Taxonomy object).

InstantResults::get_facets() currently assumes each filtered taxonomy entry is a WP_Taxonomy object and passes it directly to get_taxonomy_labels(). If a third-party integration appends a slug string, WordPress core fatals when it tries to treat a string as an object (e.g., Attempt to assign property "labels" on string in wp-includes/taxonomy.php).

This change adds a defensive guard in the taxonomy facets loop:

  • If the value is a string slug, normalize it via get_taxonomy( $slug )
  • If the value cannot be resolved to WP_Taxonomy, skip it

This prevents wp-admin lockouts while preserving existing behavior for correctly shaped data.

Closes #4254

How to test the Change

  1. Install and activate ElasticPress 5.3.2 and enable Instant Results.
  2. Add the reproduction filter from issue BUG: Fatal error in Instant Results facets when ep_facet_include_taxonomies contains a taxonomy slug string (e.g. internal_tags) #4254 (appends internal_tags as a string via ep_facet_include_taxonomies).
  3. Log in to wp-admin and visit:
    • /wp-admin/
    • /wp-admin/admin.php?page=elasticpress
  4. Confirm both pages load successfully and no fatal error occurs.

Verified on: WordPress 6.9; PHP 8.4.

Changelog Entry

Fixed - Prevent fatal error in Instant Results facets when ep_facet_include_taxonomies returns non-WP_Taxonomy values.

Credits

Props @laraib15

Checklist:

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.

BUG: Fatal error in Instant Results facets when ep_facet_include_taxonomies contains a taxonomy slug string (e.g. internal_tags)

1 participant