# Correct syntax for related blog posts by topic/category

**URL:** <https://community.hubspot.com/t/correct-syntax-for-related-blog-posts-by-topic-category/80778>\
**Category:** CMS Development\
**Created:** [May 8, 2023, 7:02pm UTC](https://community.hubspot.com/t/correct-syntax-for-related-blog-posts-by-topic-category/80778 "2023-05-08T19:02:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmcmillan99](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tmcmillan99/32/93181_2.png) [@tmcmillan99](https://community.hubspot.com/u/tmcmillan99)\
**Post date:** [May 8, 2023, 7:02pm UTC](https://community.hubspot.com/t/correct-syntax-for-related-blog-posts-by-topic-category/80778/1 "2023-05-08T19:02:25Z")

</div>

What is the correct syntax to filter the blog post by the categories listed in the post\_tags variable?

{% set post\_tags = content.topic\_list|map(‘name’)|join(‘,’) %}  
{% set related\_posts = blog\_recent\_posts(‘default’, 3, post\_tags) %}

I don’t believe I have this part correct - (‘default’, 3, post\_tags)

Thanks,

Terry McMillan

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [May 9, 2023, 5:08am UTC](https://community.hubspot.com/t/correct-syntax-for-related-blog-posts-by-topic-category/80778/2 "2023-05-09T05:08:04Z")

</div>

Hello @tmcmillan99  
The syntax for filtering the blog post by the categories listed in the post\_tags variable depends on how your HubSpot blog is set up and the type of filter you want to apply. Here are a few examples.  
Filter by exact match on a single category

```lia-code-sample
{% set related_posts = blog_recent_posts('default', 3, category=post_tags) %}

```

Filter by exact match on multiple categories

```lia-code-sample
{% set post_tags_array = post_tags.split(',') %}
{% set related_posts = blog_recent_posts('default', 3, categories=post_tags_array) %}

```

Filter by partial match on multiple categories

```lia-code-sample
{% set post_tags_array = post_tags.split(',') %}
{% set related_posts = blog_recent_posts('default', 3, categories_contains=post_tags_array) %}

```

In the first example, the category parameter is used to filter the blog posts by a single category. In the second example, the categories parameter is used to filter the blog posts by an array of categories. In the third example, the categories\_contains parameter is used to filter the blog posts by an array of categories, matching partial matches.

---

<div class="post-metadata">

**Author:** ![tmcmillan99](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tmcmillan99/32/93181_2.png) [@tmcmillan99](https://community.hubspot.com/u/tmcmillan99)\
**Post date:** [May 9, 2023, 6:50pm UTC](https://community.hubspot.com/t/correct-syntax-for-related-blog-posts-by-topic-category/80778/3 "2023-05-09T18:50:08Z")

</div>

@himanshurauthan

Thank you for the code examples. Unfortunately, I am unable to get them to work correctly. It still renders the 3 most recent blog posts instead of using the category from the viewed post. I did verify that the post\_tags variable contains the correct post category (using {{ post\_tags }} ). I even tried using a specific category to see if that would work - blog\_recent\_posts(‘default’, 3, category=‘Website Design’) but still received the same results.

Any other suggestions on what I can try?

---

<div class="post-metadata">

**Author:** ![tmcmillan99](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tmcmillan99/32/93181_2.png) [@tmcmillan99](https://community.hubspot.com/u/tmcmillan99)\
**Post date:** [May 9, 2023, 8:10pm UTC](https://community.hubspot.com/t/correct-syntax-for-related-blog-posts-by-topic-category/80778/4 "2023-05-09T20:10:23Z")

</div>

I was able to get it working with the following code-

{% set related\_posts = blog\_recent\_topic\_posts(“default”, content.topic\_list[0].slug, 3) %}
