我想获得过去x天评论最多的帖子,我有以下代码:
<?php
global $wpdb;
$weekstart = date(\'Y-m-d\', strtotime(\'-12 days\'));
$query = $wpdb->prepare("
SELECT comment_post_id, count( comment_post_id ) AS c, SUBSTRING( comment_date,1, 5 ) AS d
FROM $wpdb->comments
WHERE (comment_date >= %s)
GROUP BY comment_post_id
ORDER BY c DESC, d DESC ",$weekstart);
$col_ids = $wpdb->get_col($query);
if ($col_ids) {
$postids = implode($col_ids,\', \');
echo $postids;
function filter_orderby($orderby = \'\') {
global $postids;
$orderby = " FIELD(ID,$postids )";
echo $orderby;
return $orderby;
}
add_filter(\'posts_orderby\', \'filter_orderby\');
?>
我想按id过滤帖子,问题是回显$orderby(用于测试)会返回以下内容:字段(id,)
而不是实际的顺序,该字段无法识别,并且$PostId为空。我错过了什么?我怎样才能让它正常工作?非常感谢。