当前帖子的第一条评论ID

  • 本文关键字:一条 评论 ID wordpress
  • 更新时间 :
  • 英文 :


有人知道如何从当前帖子获得第一个评论ID吗?

我一直在寻找一个好的解决办法,但没有找到合适的。

谢谢你的帮助。

get_comments()返回一个对象。所以你可以像访问其他对象一样访问第一个:

$comments = get_comments();
$first_comment_id = $comments[0]->comment_ID;

您必须使用以下函数来获取帖子的评论

<?php get_comments( $defaults ); ?>

默认用法如下:

<?php 
$defaults = array(
'author_email' => '',
'author__in' => '',
'author__not_in' => '',
'include_unapproved' => '',
'fields' => '',
'ID' => '',
'comment__in' => '',
'comment__not_in' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_author__in' => '',
'post_author__not_in' => '',
'post_ID' => '', // ignored (use post_id instead)
'post_id' => 0,
'post__in' => '',
'post__not_in' => '',
'post_author' => '',
'post_name' => '',
'post_parent' => '',
'post_status' => '',
'post_type' => '',
'status' => 'all',
'type' => '',
    'type__in' => '',
    'type__not_in' => '',
'user_id' => '',
'search' => '',
'count' => false,
'meta_key' => '',
'meta_value' => '',
'meta_query' => '',
'date_query' => null, // See WP_Date_Query
);
?>

确保根据您的需求编辑值。使用get_comments(),你可以获得所有的评论,这样你就可以获取第一个或任何必要的评论id使用循环。

最新更新