按WordPress中的当前用户ID过滤帖子

时间:2017-06-27 16:05:00

标签: wordpress

我正在使用插件Post View Stats我希望能够使用我的个人帖子(带日期范围过滤器)的统计信息显示表格。该插件已经提供了一个表,但我想过滤当前登录用户发布的帖子,以便为我的作者提供一些统计信息。

选择日期的第一部分

if( !defined('ABSPATH') ) die('-1');
global $wpdb;
$table_name = $wpdb->prefix . "cn_track_post";
if(isset($_POST['to']) and isset($_POST['from'])) {
    $select = "SELECT *,count(*) as counts FROM $table_name WHERE create_date >='".$_POST['from']."' AND create_date<='".$_POST['to']."' group by post_id order by counts desc LIMIT 0,100";
} else {
    $select = "SELECT *,count(*) as counts FROM $table_name WHERE 1 group by post_id order by counts desc LIMIT 0,100";
}
$tabledata = $wpdb->get_results($select);

显示每个帖子的第二部分

$i=1;
foreach($tabledata as $data) { 
$posts = get_post($data->post_id); 
$title = $posts->post_title;
$user_info = get_userdata($posts->post_author);

数据库结构:cn_track_post

id / post_id / created_at / create_date

$insert = "INSERT INTO " . $table_name . "( post_id, created_at, create_date ) VALUES (" . $post->ID . ",'" . time() . "','" . date('Y-m-d')."')";

0 个答案:

没有答案