CMS Development

swapnilmr
Member

Avoid duplication for displaying blog post if it has multiple tags

SOLVE

I'm displaying multiple posts on my Website Page with the help of custom module. I'm pulling post with the help of following code:

 

{% set topic_one = blog_recent_topic_posts('BLOG ID', topic_name_1, 10) %}
{% set topic_two = blog_recent_topic_posts('BLOG ID', topic_name_2, 10) %}
{% set topic_three = blog_recent_topic_posts('BLOG ID', topic_name_3, 10) %}

{% set topic_posts = (topic_one + topic_two + topic_three)|sort(true, false, 'publish_date') %}

{% for topic_post in topic_posts %}
Post content
{% endfor %}

 

The problem is, if the blog post has both topic_one and topic_two tagged, then that blog post will get displayed twice. I want to avoid this duplication. Can anyone help me with this?

 

0 Upvotes
1 Accepted solution
Jsum
Solution
Key Advisor

Avoid duplication for displaying blog post if it has multiple tags

SOLVE

Use the unique Hubl filter

{% for topic_post in topic_posts|unique %}
Post content
{% endfor %}

I've had this issue before and I am pretty sure that is how I got it to work.

View solution in original post

0 Upvotes
2 Replies 2
Jsum
Solution
Key Advisor

Avoid duplication for displaying blog post if it has multiple tags

SOLVE

Use the unique Hubl filter

{% for topic_post in topic_posts|unique %}
Post content
{% endfor %}

I've had this issue before and I am pretty sure that is how I got it to work.

0 Upvotes
swapnilmr
Member

Avoid duplication for displaying blog post if it has multiple tags

SOLVE

Thank you, this works!

0 Upvotes