0

I have a WP_Query on my homepage template that works just fine for get_the_title() and MANY other functions for each post in the loop.

However, any way of getting the comment count just grabs the real count for the first post and then repeats the same output for the rest of the posts.

I've tried both echo get_comments_number($post->ID); and comments_number();

The kicker: if I use the same template NOT on the homepage, comment count works fine.

  • I would paste my code here but it's a very complex template for handling many post types. Can do a pastebin if required. – jetlej Nov 24 '14 at 2:28
  • Try wp_reset_postdata() or wp_reset_query(). If it doesn't work, please paste the full code of homepage template in pastebin. – Ashok Kumar Nath Nov 24 '14 at 7:33
0

Switching out echo get_comments_number($post->ID) for echo $post->comment_count did the trick.

I have no idea why, that's exactly what the get_comments_number() function does...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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