开发者

Can't echo wp_count_posts('page')?

开发者 https://www.devze.com 2022-12-18 16:46 出处:网络
I\'m trying to echo the value of the variable in the code below. I\'m getting an error 开发者_开发百科(see below)...

I'm trying to echo the value of the variable in the code below. I'm getting an error 开发者_开发百科(see below)...

Here's the code...

$mypagecount = wp_count_posts('page');
echo $mypagecount;

Here's the error:

Catchable fatal error: Object of class stdClass could not be converted to string


The wp_count_posts function returns an object.
You can ask the object to return the number of publish items.

<?php
     $count_pages = wp_count_posts('page');
     $pages = $count_pages->publish;
     echo $pages;
?>

For more information:
http://wpengineer.com/show-amount-of-posts-pages-categories-tags-comments-for-wordpress-themes/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号