categories - Catchable fatal error: Object of class WP_Term could not be converted to string

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

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?

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?

Share Improve this question edited Feb 19, 2017 at 23:32 xvilo 3661 silver badge13 bronze badges asked Feb 19, 2017 at 21:14 OgalaOgala 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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:

$mycategory=get_category_by_slug('a-category-slug');
$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:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745319380a4622372.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信