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