代碼如下:
<?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
---------------