admin管理员组文章数量:1379636
I need a way to get just the comments that aren't top level i.e. where parent is not 0.
I've tried:
$args = array(
'parent' => -0
);
$comments = get_comments($args);
I know the parent comment id's (44 and 48) of all the comments I require, so I tried:
$args = array(
'parent' => array(44,48)
);
$comments = get_comments($args);
But this didn't work. It only returned one row. I need to stick with get_comments() if possible, as I've done a lot of work around it already so want to avoid losing what I've done.
I need a way to get just the comments that aren't top level i.e. where parent is not 0.
I've tried:
$args = array(
'parent' => -0
);
$comments = get_comments($args);
I know the parent comment id's (44 and 48) of all the comments I require, so I tried:
$args = array(
'parent' => array(44,48)
);
$comments = get_comments($args);
But this didn't work. It only returned one row. I need to stick with get_comments() if possible, as I've done a lot of work around it already so want to avoid losing what I've done.
Share Improve this question edited Jan 6, 2013 at 23:01 Chris asked Jan 6, 2013 at 22:55 ChrisChris 4532 gold badges15 silver badges31 bronze badges2 Answers
Reset to default 5You cannot do that with a parameter for get_comments()
, but filtering 'comments_clauses'
should do it.
Sample code, not tested:
add_filter( 'comments_clauses', 'wpse_78490_child_comments_only' );
function wpse_78490_child_comments_only( $clauses )
{
$clauses['where'] .= ' AND comment_parent != 0';
return $clauses;
}
Get comments of a specific comment parents...
(If you are not forced to do it with get_comments()
)
You can pass an array of comments to wp_list_comments()
as the second argument.
It will only work with ‘flat’ output, though.
$comments_parent_ids= [40, 48];
$comments= [];
foreach ($comments_parent_ids as $id) {
$comments= array_merge(
$comments,
get_comment($id)->get_children(['hierarchical'=>'flat'])
);
}
wp_list_comments(
[],
$comments
);
本文标签: commentsgetcomments() where parent is not 0
版权声明:本文标题:comments - get_comments() where parent is not 0 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744470013a2607741.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论