I found this post that describes how to filter category posts with Ajax and it works great, but I also want to filter my custom taxonomies the same way and I can’t get it to work. It shows me all posts instead of just the posts from my taxonomy.
I know the menu needs to be changed to get_the_terms
instead of get_the_categories
but I specifically need help with what to change in the jQuery function and the php function at the bottom. I tried adding a tax_query
calling my taxonomy but it’s still not showing the correct posts. Can anyone help point me in the right direction?
I figured it out! Here is the code I used:
Add to
functions.php
:jQuery script:
I’m not using a function to list the categories, I’m just listing each of them separately. Replace the number with the ID of your term:
Also, if you want to filter tags instead of terms, replace:
'term'
with'tag__in'
,$term_id
with$tag_id
'taxonomy' => 'yourtaxonomyhere'
to'taxonomy' => 'post_tag'
.I suggest that you use a shortcode to display taxonomy of your choice :
create a class to declare the shortcode and call this function
http://www.webmasterbulletin.net/wordpress-ajax-taxonomy-search-shortcode
I had a similar problem.
The code is good, but it needs to small modify to work.