WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some custom comments fields, I need to display the number of times that a meta value is used

Example :

I have a custom comments field "Do you like this post" with multiple choice :

  • Yes

  • No

I need to display how much person say "Yes", how much say "No" for each post, It's an example. Don't tell me to use "post rating" plugins ;)

share|improve this question
Your question isn't clear. You want the number of times the meta_value is set, whether "yes" or "no"? The number of "yes" votes for all posts? The number of "yes" votes per post, or for a single post? – s_ha_dum Mar 27 '13 at 14:08

I would try something like this:

$comments = get_comments();
$yes = 0;
$no = 0;
foreach ($comments as $comment) {
    $vote = get_comment_meta ( $comment->comment_ID, 'vote', true );
    if ($vote == 'yes') {
    } else if ($vote == 'no') {
echo 'Yes:'.$yes.' No:'.$no;

Problem is the numbers can easily be manipulated so it might be better to count only one vote per user_id, comment_author or comment_author_IP depending on your usage.

Codex: get_comments - get_comment_meta

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.