实现功能如题,是通过通过用户ID查询数据库来获取评论总数。
<code>
<?php
global $wpdb;
$author_id = $current_user->ID;
$comment_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved='1' AND user_id = '$author_id' AND comment_type not in ('trackback','pingback')" )); //查询作者评论数量
$post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('publish','static') AND post_author = '$author_id' AND post_type = 'iask' ") ); //查询作者文章数量
?></code>
<?php
global $wpdb;
$author_id = $current_user->ID;
$comment_count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved='1' AND user_id = '$author_id' AND comment_type not in ('trackback','pingback')" )); //查询作者评论数量
$post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status IN ('publish','static') AND post_author = '$author_id' AND post_type = 'iask' ") ); //查询作者文章数量
?></code>
食用方法
<code>
<?php
echo $comment_count;//输出评论数量
//echo $post_count;//输出文章数量
?></code>
<?php
echo $comment_count;//输出评论数量
//echo $post_count;//输出文章数量
?></code>