humanmade / aws-analytics

AWS Pinpoint analytics for WordPress
https://www.altis-dxp.com/
19 stars 1 forks source link

Only set taxonomy parameters when not searching #541

Closed kadamwhite closed 1 year ago

kadamwhite commented 1 year ago

If you use category__in on a search query, is_category() will return true even though is_search() also returns true. This causes a log warning in PHP 8,

[04-Nov-2022 18:45:19 UTC] PHP Warning:  Attempt to read property "taxonomy" on null in /usr/src/app/vendor/altis/aws-analytics/inc/namespace.php on line 163
[04-Nov-2022 18:45:19 UTC] PHP Warning:  Attempt to read property "slug" on null in /usr/src/app/vendor/altis/aws-analytics/inc/namespace.php on line 164

If we alter the check to only add taxonomy parameters if on a non-search-results page, the queried object will have the expected properties.

An alternative solution would be to add

&& isset( get_queried_object()->taxonomy )

to the condition chain.