The function get_comments
allows you to select comments based on meta value. So, supposing you are on a single post page, so the current post is known, you would do this:
$comments = get_comments (array ('meta_key'=> 'your_meta_key'));
This will give you all comments with that specific meta key. You can even select them for a specific meta value, like this:
$comments = get_comments (array ('meta_key'=> 'your_meta_key', 'meta_value'=> 'your_meta_value'));
For instance, if you have a meta key called ‘rating’ and you want all comments that give the rating ‘5’, you would do:
$comments = get_comments (array ('meta_key'=> 'rating', 'meta_value'=> '5'));
Beware that $comments
returns as an array of comment objects, so printing goes like this:
foreach($comments as $comment) {
echo ($comment->comment_content);
echo get_comment_meta($comment->comment_ID, 'rating', true)
}