How would I count (and display) the number of times a comment meta field's value is a post's entire comments?
e.g. meta key is "fish" and key value "shark" appears in 5 comments of a post.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
You should be able to do a
meta_query in a
$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 );
WP_Comment_query() accepts a
'post_id' so you can search withing a specific post's comments.