这只花了我三天时间,但我终于拼凑好了。我知道这不是过去的24小时,但这是一个24小时的周期,我可以很容易地更改日期。这些日期用于测试我用标签发布的帖子。
$date1 = \'2016-07-20 00:00:00\';
$date2 = \'2016-07-21 00:00:00\';
$sql = $wpdb->prepare("
SELECT taxonomy.term_taxonomy_id AS termId, COUNT( * ) AS count, relatedTerms.*
FROM celebnew_term_taxonomy AS taxonomy
JOIN (
SELECT *
FROM celebnew_term_relationships related
JOIN (
SELECT *
FROM celebnew_posts AS posts
WHERE posts.post_date > \'%s\'
AND posts.post_date < \'%s\'
AND posts.post_status = \'publish\'
ORDER BY posts.post_date ASC
)24HrPosts ON 24HrPosts.ID = related.object_id
)relatedTerms ON relatedTerms.term_taxonomy_id = taxonomy.term_taxonomy_id
WHERE taxonomy.taxonomy = \'post_tag\'
GROUP BY taxonomy.term_taxonomy_id
", $date1, $date2);
$slebs = $wpdb->get_results($sql);
var_dump($tags);
如果有人有任何建议,我希望看到一个更干净的版本,但现在这就是我要做的。