related_blog_posts only shows some posts from blog

kevinpotts
Member

Hello everyone. I have been trying to understand why related_blog_posts only returns some blog posts whether using default rendering, callback or post_formatter. Basic code:

 

 

{% related_blog_posts blog_ids="555555555555" callback="news_headlines" limit=3 %}
<script>
  var news_headlines = function(blogposts) {
    var formatted = "<div>";
    for (var i = 0; i < blogposts.length; i++) {
      var blogpost = blogposts[i];
      formatted += '<div class="blog-list only-headlines press-releases">';
      formatted += `<span class="blog-list-date">${new Date(blogpost.publishDate).toLocaleDateString()}</span>`;
      formatted += `<a class="blog-list-title" href="${blogpost.url}">${blogpost.name}</a>`;
      formatted += '</div>';
    }
    formatted += '</div>';
    return formatted;
  }
</script>

 

 

I know this code functions because it renders one post. Unfortunately, it only renders ONE post. Is it possible that there is a delay in the CMS system actually accessing the HubSpot contentdatabase?

 

I ask because the post that is rendering was added a few days ago. The post that won't render was added an hour ago. I double-checked everything and they are functionally identical: same blog, same author, same language, neither have tags, both published within last 30 days, etc. Only the actual content is different.

 

Any ideas?

0 Upvotes
6 Replies 6
miljkovicmisa
Top Contributor | Gold Partner

Hello @kevinpotts  and thank you for writing.

If you are using this function on a blog post template you should omit the blog_post_ids parameter as per the documentation:

Please note that if the related_blog_posts HubL tag is being used on a post, the blog_post_ids parameter should not be specified, as on blog posts, it will default to the post the widget is appearing on.

Otherwise if that's not the issue, please post some more details or a link to your page so we could debug it.

If my answer was helpful please mark it as a solution.

kevinpotts
Member

I am not using this on a blog post template. It is used on a page template. The concept is an "About" page that pulls in recent press release headlines. I've done this before using the RSS tag, but that feels a bit sloppy and I would like more explicit control over the markup.

0 Upvotes
josh_dev
Contributor

Do you have a live or test version I could check out? I'm happy to figure this out for you.

kevinpotts
Member

Just to report back in, the script is now working. I have made no changes. Perhaps my suspicion is true: something cached on the server side was not allowing more recent items to publish in the feed.

0 Upvotes
Teun
Key Advisor | Diamond Partner

@kevinpotts I've had some issues with related blogs and popular blogs showing up. Most of the time you have to wait a few hours for them to show up.
If it is a cache related issue, make sure to install the HubSpot Developer Extension. It has a bust cache option to make sure you are looking at the most recent version of your page (great when developing). 

P.S. The debug param is pretty handy too.



Did my answer solve your issue? Help the community by marking it as the solution.
kevinpotts
Member

Great tip on the Chrome extension. Thank you.

0 Upvotes