我如何计算(并显示)评论元字段的值是一篇文章的全部评论的次数?
e、 元键是“鱼”,键值“鲨鱼”出现在一篇帖子的5条评论中。
我如何计算(并显示)评论元字段的值是一篇文章的全部评论的次数?
e、 元键是“鱼”,键值“鲨鱼”出现在一篇帖子的5条评论中。
你应该能够meta_query
在a中WP_Comment_Query()
:
$args = array(
\'post_id\' => \'post-id-here\',
\'meta_query\' => array(
array(
\'key\' => \'fish\',
\'value\' => \'shark\',
\'compare\' => \'LIKE\'
)
)
);
// Query the comments
$comment_query = new WP_Comment_Query( $args );
// Count the number of comments
$count = count ( $comment_query );
TheWP_Comment_query()
接受\'post_id\'
因此,您可以搜索特定帖子的评论。我正在自定义具有以下代码的主题以显示注释:if ( have_comments() ) : ?> <h2 class=\"comments-title\"> <?php printf( // WPCS: XSS OK. esc_html( _nx( \'One thought on “%2$s”\', \'%1$s thoughts