Get Count of All Approved Comments on a Post

Home » Snippets » Get Count of All Approved Comments on a Post
0

Created with:

WP_Comment_Query Generator

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
				$query_args = array(
	'count' => true,
	'status' => 'approve',
	'type' => 'comment',
	'post_name' => 'post-slug',
	'number' => 10,
	'order' => 'DESC',
);

$query = new WP_Comment_Query( $query_args );

if ( ! empty( $query ) && ! is_wp_error( $query ) ) {
	foreach ( $query as $comment ) {
		// do something
	}
}
else {
	// no terms found
}
			

Register an account to save your snippets or go Pro to get more features.