CMS Development

kpkreative
Participant

Blog Post Filter Dropdown not working

SOLVE

Screenshot 2021-01-22 at 15.04.11.pngScreenshot 2021-01-22 at 15.04.27.pngI have added a dropdown tag filter to my blog, though for some reason, it is not displaying the tags of the posts that are published in the dropdown. Strangely i have used this method for other blogs before without any issues. 

 

The dropdown displays visually as it should, though published tags do not show from the dropdown list. 

I have used the following code within my blog listing template:

 

<div class="tag-dropdown">
      {% set my_topics = blog_topics('default', 250) %}
<select id="blog-topics">
<option>Filter by topic</option>
{% for item in my_topics %}
<option value="{{ blog_topic_url(group.id, item.slug) }}">{{ item }}</option>
{% endfor %}
</select>
         </div>
 
JS
 

<script>
$(function(){
$('#blog-topics').on('change', function(){
var link = $(this).val();
if(link != "Filter by topic"){
window.location.href = link;
}
});
});
</script>

 

Any suggestions would be hugely appreciated.

 
 
0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

Blog Post Filter Dropdown not working

SOLVE

The blog_topics function has been deprecated, you should use blog_tags instead. Also blog_tag_url instead of blog_topic_url.

{% set my_topics = blog_tags('default', 250) %}       

{{ blog_tag_url(group.id, item.slug) }}

View solution in original post

2 Replies 2
kpkreative
Participant

Blog Post Filter Dropdown not working

SOLVE

Piers, you are na absolute hero. Thank you so much for your feedback on my post. 

I was not aware of the 'blog_topics being deprecated. I last used this method around 6 or so months ago, so it's great to finally see a solution.


I appreciate your time. Thank you once again.

piersg
Solution
Key Advisor

Blog Post Filter Dropdown not working

SOLVE

The blog_topics function has been deprecated, you should use blog_tags instead. Also blog_tag_url instead of blog_topic_url.

{% set my_topics = blog_tags('default', 250) %}       

{{ blog_tag_url(group.id, item.slug) }}