Blog Post Issue - Similar Posts

Hello :slightly_smiling_face:
I think ave found a critical bug in HubSpot that I cannot find a solution for.

After reading all the HubSpot documentation and comparing it with other projects and HubSpots I manage, I’ve concluded that this is an issue on HubSpot’s part that I can’t fix it :disappointed_face: I think.
I’ll try to explain.
I have a blog with different articles, and each blog post has only one associated tag (not multiple). At the end of each article, there is a “Similar posts” section. However, when I use the code to fetch similar posts and print the tag variable I am passing as a parameter, it does not return the correct results.
For example, if I open a post with the tag “Recruitment,” it works fine, but with the tag “sales,” it does not work.
And if you check my code screenshots, you can see that everything is correct and the variable containing the tag is printing correctly. So, I don’t understand how a post with the tag “sales” is showing related posts that are not about sales.


Sales Tag

Recruitment Tag


Sales Tag post

Recruitment Tag Post

@JDoxy07 this is interesting, thank you for sharing so much detail and screenshots to explain the issue.

Non-code question - on the blog, are there enough posts tagged “sales” to fill the 6 related post spots (at least 6)? or are there only the 3 shown?

Is the desired behavior that you only want the 3 sales posts to show, if there aren’t more?

Hello @Jnix284 thank you for your message.
I was expecting someone to raise that question. :grinning_face_with_smiling_eyes:

But it’s all right because, for instance, I have 8 articles in total with the tag ‘Sales’ and 10 with the tag ‘Recruitment.’

So, as I have a limit of 6, everything should be displaying correctly. :disappointed_face:

Thanks for the additional details @JDoxy07, thats what I suspected, I just wanted to be sure.

Without being able to dig into the code and try to recreate the issue, I’m not sure how else I can help - it looks like you have identifying info blurred and can’t share the code or link directly.

Perhaps @Anton can spot something in the code that you and I have missed.

Thanks for thinking of me @Jnix284 :grin:

Hi @JDoxy07,

without seeing the code as a whole it’s quite hard to tell what might be off but the one thing that seems to be a bit off is the

{% if featured_tag %}
...
{% else %}
...
{% endif %}

statement.

The only thing it does is checking if there’s any tag available. Unless you’re checking for “if featured_tag equals post_tags” somewhere in your code/macro it will only do the following:

“If tag is available show posts with the tag - else - show other posts”

And this is what your code does. So I’d assume that there’s no logic that matches the featured_tag to post_tags.

Have you tried something like this:

{% if featured_tag == post_tags[0] %}
...
if the post_tag matches
{% else %}
...
if the post_tag doesn't match
{% endif %}

best,

Anton

Moderator note: While this solution may not address the original poster’s specific situation, it could be helpful for other community members facing similar challenges.

Hello @Anton thank you for your message.

I understand your message

However, the feature_tag and the post_tag are exactly the same.

I included both approaches so you could see and verify through data-feature-tags and data-posts-tags what the variables were outputting at that moment.

And as you can see, they are printing correctly.

They always enter the first if statement.

So, it should have been done correctly.

Remember that removing the if statements and leaving just this instruction:

{% related_blog_posts limit=6, no_wrapper=True, post_formatter="recent_post", tags="Sales"%}

Directly placing, for example, the tag “sales” still lists some posts that are not “sales” as shown in the images.

Do you understand the problem now?

thanks

Hello @Jnix284 thanks a lot for you help.
The information that is blurred is just the blog post title. It’s only important to check that the tags on the images are correct.
And in the code, I simply applied a blur to the name of a class. :slightly_smiling_face: