我正在尝试设置自定义WP_Comment_Query
按元键排序。(值得一提的是,这些注释是通过AJAX检索的。)
在我将分页添加到查询参数之前,一切都很好。
$orderby = \'top-comments\';
$args = array(
\'post_id\' => $post_id,
\'type\' => \'comment\',
\'status\' => \'approve\',
\'hierarchical\' => true
);
if ( $orderby == \'top-comments\' ) {
$args[\'meta_key\'] = \'comment_rating\';
$args[\'orderby\'] = \'meta_value_num\';
$args[\'order\'] = \'ASC\';
}
// $comments_query = new WP_Comment_Query;
// $comments = $comments_query->query($args);
// Works fine up until I add the pagination args
$number = 5;
$paged = 1;
$args[\'number\'] = $number;
$args[\'paged\'] = $paged;
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query($args);
// Gets the 5 latest comments, then orders those by meta_key
没有分页参数的结果工作得很好,并且按我想要的方式排列注释。但是,一旦设置了number参数,它将检索最新的5条注释,然后按排序meta_key => \'comment_rating\'
.
我期望的行为是WP\\u Comment\\u Queryfirst 应用orderby,以及then 返回前5个结果。
我做错了什么?