简体   繁体   English

WordPress“ wp_list_comments”自定义顺序

[英]WordPress “wp_list_comments” custom order

I'm using WordPress 3.0.1 and want to order the comments from a post using a rating custom field. 我正在使用WordPress 3.0.1,并希望使用评级自定义字段从帖子中订购评论。

Is this possible? 这可能吗? I'm already using the callback property from wp_list_comments to customize the appearance of the comments. 我已经在使用wp_list_comments的callback属性来自定义注释的外观。

Unfortunately this way I can only access the comments one by one and can't affect the order of the all result array. 不幸的是,这样我只能一个接一个地访问注释,而不会影响所有结果数组的顺序。

I've already have a table with all the votes from the users. 我已经有一张桌子,上面有用户的所有投票。

Thanks in advance. 提前致谢。

// get comments of post 1234
$comments = get_comments( array('post_id' => 1234) );

// ... order your comments collection using php (eg. usort) here ...

// print your comments
wp_list_comments( array( 'callback' => 'woocommerce_comments' ), $comments);

Try $comments = get_comments('postId=x'); 尝试$comments = get_comments('postId=x'); . It should be indexed by comment id. 它应该通过评论ID索引。 You can then look up the comment rating in your table. 然后,您可以在表格中查找评论评分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM