admin管理员组文章数量:1122832
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 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.
Share Improve this question asked Nov 24, 2014 at 2:28 jetlejjetlej 5721 gold badge6 silver badges24 bronze badges 2- 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 Commented Nov 24, 2014 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 Commented Nov 24, 2014 at 7:33
1 Answer
Reset to default 0Switching 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...
本文标签: wp queryComment count same for every post in homepage WPQuery
版权声明:本文标题:wp query - Comment count same for every post in homepage WP_Query 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287844a1927969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论