在WordPress中插入评论时,我正在使用自定义评论类型“博客”。例如:
wp_insert_comment( array(
'comment_post_ID' => $args['post_id'],
'comment_content' => wp_filter_post_kses( $args['content'] ),
'comment_type' => 'blog',
'user_id' => $args['user']->ID,
'comment_author' => $args['user']->display_name,
'comment_author_email' => $args['user']->user_email,
'comment_author_url' => $args['user']->user_url,
) );
如何获得每个帖子的评论数?以下内容对我不起作用,因为它显示了'comment'类型的评论计数。我需要显示“博客”类型评论的总数。
wp_count_comments( $post_id );
您可以使用get_comments()
:
$count = count( get_comments( array(
'post_id' => get_the_ID(),
'type' => 'blog'
) ) );
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句