I am getting an error while trying to display certain categories on my Wordpress Site. This is the error message:

Catchable fatal error: Object of class WP_Term could not be converted to string in ...public_html/wp-includes/class-wp-query.php on line 780

line 780 :

$qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] );

The error only happens for parent categories without a special archive template. Anyone with an idea what I got wrong?


Your problem isn't line 780 of ../wp-includes/class-wp-query.php

So it's a little bit hard to help because you're not showing the actual code that's at fault.

But you're probably trying to reference a post category by its data object instead of using the integer id.

For example you might have something like this:

$args = array( 'posts_per_page' => -1, 'category' => $mycategory);
$myposts = get_posts( $args );

But $mycategory is an object, not an integer value.

You would need to add ->term_id to get its integer value:

$args = array( 'posts_per_page' => -1, 'category' => $mycategory->term_id);
$myposts = get_posts( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.