WordPress 获取某人某天或者某人所有文章数

define('WP_USE_THEMES', false); //无需使用主题
include_once('./wp-load.php');  //根据wordpress路径来调用 需要同服务器下
//获取某人某天的发帖量,不传$date为某人所有文章数
function get_posts_count($userid,$date) {
    global $wpdb;
    if($date){
    $numposts = $wpdb->get_var(
        $wpdb->prepare("SELECT COUNT(ID) FROM `wp_posts`  WHERE  
        `post_author` = $userid
        AND post_type= 'post'
        AND post_status= 'publish'
        AND post_date between '$date 00:00:00' and '$date 23:59:59';")
        );
    }else{
    $numposts = $wpdb->get_var(
        $wpdb->prepare("SELECT COUNT(ID) FROM `wp_posts`  WHERE  
        `post_author` = $userid
        AND post_type= 'post'
        AND post_status= 'publish';")
        );
    }
    return $numposts;
}
© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享