代码如下:
<?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’” ) ); //查询作者文章数量
?>
----
关于 get_var,$wpdb->get_results , get_row , get_col,$wpdb->insert,$wpdb->replace , $wpdb->update, $wpdb->delete 的文档:
https://codex.WordPress.org/Class_Reference/wpdb
wpdb 和 wp_query 的区别:
http://www.tv-wp.com/wp_query_posts.html
------------------
自定义 WordPress 查询的 4 种方法 :
通过改变 query_posts($args) 的参数修改主循环
通过 WP_Query Class
通过 filters 更改 query_posts() 产生的 SQL 语句
通过 $wpdb 自定义 SQL 语句
http://www.solagirl.net/alter-WordPress-query-in-four-ways.html
---------------