wordpress API

WordPress如何获得示作者文章数量和评论数量,wpdb , get_var

日期:2015-04-16 阅读:1718

dmandwp系统 - wordpress系统和DM系统区块建站>>

代码如下:

<?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

---------------

 

<<点击返回