Debugging ‘Object of class WP_Query could not be converted to int’ error

The issue if that your conditional is trying to convert an Object into things that it cannot be converted to. WP_Query returns a WP_Query Object so when it’s tested against Object == 0 – it tries to convert the object into a number during the comparison but cannot.

You instead need to test against $results->have_posts() or one of it’s properties such as 0 === $results->found_posts

Leave a Comment