BUG: EP crashes trying to use queried object that doesn't exist
Describe the bug
This code in includes/classes/Indexable/Post/QueryIntegration.php assumes that $query->get_queried_object() always returns a term, this is not a safe assumption:
if ( empty( $query_vars['post_type'] ) ) {
if ( $query->is_tax() ) {
$query_vars['post_type'] = get_taxonomy( $query->get_queried_object()->taxonomy )->object_type;
} elseif ( empty( $query_vars['s'] ) ) {
Steps to Reproduce
Not 100% on the steps that lead to this, only that this is what I got at the other end
Screenshots, screen recording, code snippet
No response
Environment information
No response
WordPress and ElasticPress information
latest version of elasticpress 4.4.1
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Thanks for opening the issue @tomjn but I'm curious to know how this could be a problem. Looking at the is_tax() method, it would return false if queried_object doesn't have a taxonomy set.
I'm not sure how this came about myself, I'm as surprised as you are, and yet it's there. My suspicion is that there are filters interfering here. It's on WP 5.9, no modifications have been made to WP or ElasticPress stock versions. I'm not 100% sure how to reliably reproduce it either.
At a minimum I'd separate out the chained calls to make debugging easier.