# Creating a custom post filter

**URL:** <https://community.hubspot.com/t/creating-a-custom-post-filter/19973>\
**Category:** CMS Development\
**Tags:** content\
**Created:** [April 9, 2020, 5:10pm UTC](https://community.hubspot.com/t/creating-a-custom-post-filter/19973 "2020-04-09T17:10:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DM2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dm2/32/39641_2.png) [@DM2](https://community.hubspot.com/u/DM2)\
**Post date:** [April 9, 2020, 5:10pm UTC](https://community.hubspot.com/t/creating-a-custom-post-filter/19973/1 "2020-04-09T17:10:55Z")

</div>

Hi

I’m trying to create a post filter that works with my particlular blog listing template.

My blog grabs specified tag content (there’s other content we don’t want to show)

`{% set contents = blog_recent_tag_posts('default', 'News,Events,Articles', 99) %}`

This works fine but I’d like to reload the content on the basis of filtering by a tag.

I’ve tried to create a conditional that checks for the tag name and reloads the content, in this case the ‘News’ posts, but this just reloads all the same content, even though the url slug changes accordingly to **/tag/news**

```auto
{% set contents = blog_recent_tag_posts('default', 'News,Events,Articles', 99) %}

{% if tag.name == "News" %}

{% set contents = blog_recent_tag_posts('default', 'News', 99) %}

{% endif %}

```

Could anyone point me in the right direct please?

Thanks!

---

<div class="post-metadata">

**Author:** ![DM2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dm2/32/39641_2.png) [@DM2](https://community.hubspot.com/u/DM2)\
**Post date:** [April 10, 2020, 12:00pm UTC](https://community.hubspot.com/t/creating-a-custom-post-filter/19973/2 "2020-04-10T12:00:24Z")

</div>

Ok I have a solution that works using the url slug.

Would be interested if there is a **cleaner way** to do it though!

```auto
{% set contents = blog_recent_tag_posts('default', 'News,Events,Articles', 99) %}

{% if request.path|split('/')|last == "news" %}
 {% set contents = blog_recent_tag_posts('default', 'News', 99) %}

{% elif request.path|split('/')|last == "events" %}
 {% set contents = blog_recent_tag_posts('default', 'Events', 99) %}

{% elif request.path|split('/')|last == "articles" %}
 {% set contents = blog_recent_tag_posts('default', 'Articles', 99) %}

{% endif %}

```

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [April 10, 2020, 2:13pm UTC](https://community.hubspot.com/t/creating-a-custom-post-filter/19973/3 "2020-04-10T14:13:54Z")

</div>

@DM2 I’m guessing there’s a reason why you’re not using the standard blog template that already includes this functionality? Anyway, nice work on finding a solution that works for you.

---

<div class="post-metadata">

**Author:** ![DM2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dm2/32/39641_2.png) [@DM2](https://community.hubspot.com/u/DM2)\
**Post date:** [April 10, 2020, 5:29pm UTC](https://community.hubspot.com/t/creating-a-custom-post-filter/19973/4 "2020-04-10T17:29:38Z")

</div>

yes, it’s a very heavily customised template I’ve inherited, having said that I just dragged in the post filter module and it worked fine…it didn’t before! That’s obviously the best way of doing it.
