admin管理员组文章数量:1420128
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 badges1 Answer
Reset to default 1Your 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 );
本文标签: categoriesCatchable fatal error Object of class WPTerm could not be converted to string
版权声明:本文标题:categories - Catchable fatal error: Object of class WP_Term could not be converted to string 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745319379a2653306.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论