admin管理员组文章数量:1130349
Happy new year everyone.
I've been struggling with this one for a while. I need to get the latest comment from a custom post type, but ignore any child comments i.e. only look at comments with a depth of 1.
I can get the latest comment from a custom post type using:
$args = array(
'post_type' => 'custom-post-type',
'number' => '1',
'orderby' => 'date',
'order' => 'DESC'
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
However, it doesn't take into account the depth requirement. Any ideas how I can achieve this?
Happy new year everyone.
I've been struggling with this one for a while. I need to get the latest comment from a custom post type, but ignore any child comments i.e. only look at comments with a depth of 1.
I can get the latest comment from a custom post type using:
$args = array(
'post_type' => 'custom-post-type',
'number' => '1',
'orderby' => 'date',
'order' => 'DESC'
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
However, it doesn't take into account the depth requirement. Any ideas how I can achieve this?
Share Improve this question asked Jan 1, 2013 at 12:29 ChrisChris 4532 gold badges15 silver badges31 bronze badges1 Answer
Reset to default 1Set the "parent" parameter as 0.
$args = array(
'parent' => 0,
'post_type' => 'custom-post-type',
'number' => '1',
'orderby' => 'date',
'order' => 'DESC'
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
Happy new year everyone.
I've been struggling with this one for a while. I need to get the latest comment from a custom post type, but ignore any child comments i.e. only look at comments with a depth of 1.
I can get the latest comment from a custom post type using:
$args = array(
'post_type' => 'custom-post-type',
'number' => '1',
'orderby' => 'date',
'order' => 'DESC'
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
However, it doesn't take into account the depth requirement. Any ideas how I can achieve this?
Happy new year everyone.
I've been struggling with this one for a while. I need to get the latest comment from a custom post type, but ignore any child comments i.e. only look at comments with a depth of 1.
I can get the latest comment from a custom post type using:
$args = array(
'post_type' => 'custom-post-type',
'number' => '1',
'orderby' => 'date',
'order' => 'DESC'
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
However, it doesn't take into account the depth requirement. Any ideas how I can achieve this?
Share Improve this question asked Jan 1, 2013 at 12:29 ChrisChris 4532 gold badges15 silver badges31 bronze badges1 Answer
Reset to default 1Set the "parent" parameter as 0.
$args = array(
'parent' => 0,
'post_type' => 'custom-post-type',
'number' => '1',
'orderby' => 'date',
'order' => 'DESC'
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo($comment->comment_author . '<br />' . $comment->comment_content);
endforeach;
本文标签: Get the latest comment from a custom post type where depth1
版权声明:本文标题:Get the latest comment from a custom post type where depth = 1? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749224470a2335453.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论