CMS Development

roman-nich
Member

Comments count returns zero if there is a post from a module field

Hello everyone. I created a module with custom field "Page field" and I filled in some post page from the blog. When I try to get the comments count from this page I received zero instead of two. The same code work returns the correct count for the single post page. Don't really understand what the issue is here.

{{post.comment_list|length}}


I tried to use this code:

{{post|pprint}}

And saw that list of comments is empty, but there should be two. All other fields work correctly (title, link to the post). And it displays two when I go to this page by the link.

https://share.getcloudapp.com/bLu6NOpG

Seems like neither content_by_id or blog_post_by_id functions don't return the comments count for the specific post.

0 Upvotes
6 Replies 6
lscanlan
HubSpot Alumni
HubSpot Alumni

Comments count returns zero if there is a post from a module field

Hi @roman-nich,

 

Are you still seeing this? I think you deleted blog post 6315301434 ? Is that right? If you're still seeing it somewhere, feel free to link me to the post or send along the ID and I'll be able to take a look at what's going on.

 

Thanks

Leland Scanlan

HubSpot Developer Support
0 Upvotes
roman-nich
Member

Comments count returns zero if there is a post from a module field

Hi @lscanlan. Yes, everything the same. Post id for example - 10814072414. One comment here and it return correct comment count if I use comment_count field on the post page or in the loop of posts on the listing page.

0 Upvotes
lscanlan
HubSpot Alumni
HubSpot Alumni

Comments count returns zero if there is a post from a module field

Hi @roman-nich,

 

Sorry for the delay on this. This was an issue with our content renderer where comment_list and comment_count were returning empty, even when they should be populated. The team made a change to this today. Could you check again and see if it's fixed now?

 

Thanks, and let me know if you're still seeing it.

 

Leland Scanlan

HubSpot Developer Support
0 Upvotes
OLubiarz
Member

Comments count returns zero if there is a post from a module field

Hi @lscanlan ,

 

I am facing the same issue. Already tried everything, but the counting seems not to work.  The title, post body, etc. work besides the comment counting.  Do you know what can be the reason?

{% if module.enable_module %} 
{% set posts = blog_recent_posts('default', 5) %}
 <div class="">
    <div class="">
      <h2 class=""> {{ module.check_more_text }}</h2>
     <div class="">
        {% for post in posts %} 
       {% if (loop.index > 1) and (loop.index < 5) %}
        <div class="">
          <div class="">
            <img class='' src="{{post.post_list_summary_featured_image}}" alt="img">
          </div>
          <div class="">
            <p class="">{{ post.publish_date|datetimeformat('%d/%m/%Y')  }}</p>
          </div>
          <p class="">{{ post.name }}</p>
          <p class="">{{ truncate(post.post_body|trim|striptags, 100, end='...') }}</p>
          <div class="">
            <a class="" href="{{ post.absolute_url }}">{{ module.read_more_link }}</a>
            <p class="">{{ post.comment_count }}{{ post.comment_list|length }}{{ post.comment_list }}</p>
          </div>
        </div>
        {% endif %}
        {% endfor %}
     </div>
    </div>
  </div>
{% endif %}  


 

Thanks,

Oliwia

0 Upvotes
roman-nich
Member

Comments count returns zero if there is a post from a module field

Hi @lscanlan. I've checked, and it works perfectly. Thank you so much. 

0 Upvotes
roman-nich
Member

Comments count returns zero if there is a post from a module field

Hi @lscanlan. Yes, everything the same. Post id for example - 10814072414. One comment here and it return correct comment count if I use comment_count field on the post page or in the loop of posts on the listing page.

0 Upvotes