在我的网站上,我打算显示网站上的帖子和 comments 总数,以及从我的网站购买的总数量. 我写的代码如下:
//copy to functions.php
// Total Comment
function site_total_comment_count() {
$num_comm = get_comment_count();
$num_comm = $num_comm['total_comments'];
echo $num_comm ;}
add_shortcode('total_comment_count', 'site_total_comment_count');
// Total Completed Orders
function total_completed_Orders() {
$query = new WC_Order_Query( array(
'limit' => 99999,
'status' => array( 'completed' ),
'return' => 'ids',
) );
$orders = $query->get_orders();
return count( $orders ); }
// Copy to the desired page
<h2> All Orders:
<?php echo total_completed_Orders(); ?>
</h2>
<h2> All Comments:
<?php echo site_total_comment_count(); ?>
</h2>
<h2> All Posts:
<?php
echo $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
?>
</h2>
这些代码单独运行得很好,但当我将这三个代码都放到目标页面上时,统计数据显示错误.
你能给我写一个代码,显示我网站上这三个项目的正确统计数据吗?