I have a site with multiple custom post types and taxonomies. The taxonomies are shared across all of the post types.
On the archive page of the ‘videos’ post type, I want to show a list of all of the ‘country’ tags that are associated with videos. When this link is clicked on, I’d like to be able to go to an archive for that country but that only shows the ‘videos’, not the other post types that may have the same country tag.
I also need to be able to do the same for other post types and taxonomies, e.g. when on the ‘galleries’ post type archive, a tag cloud is shown that links to the tag archive showing only the galleries.
I think that this should be easy, but I just can’t figure it out!
Will I need to create archive templates that take arguments passed via the url? E.g. mysite.com/country/canada?type=video
..and then manipulate the get_tags function somehow? I really just can’t get my head around this one.
Cheers for your help.
I’ve worked out a solution to this. I hope this can help someone else.
First add the following two functions to your functions.php (or plugin) file:
Now on your custom post type archive pages you can use
<?php show_post_type_terms('country'); ?>
, changing ‘country’ for the taxonomy that you wish to return.The links created have a query appended to the end to return only the post type that you are currently viewing. If you are on a ‘videos’ archive page it will link to a taxonomy archive showing only video posts.
I think I can answer part of this. You need a filter in your functions.php to force the loop in your tag.php template to co-operate.
Hope this helps. It’s my first go at answering a question on here 🙂
OK, I have a partial answer to my own question.
I can use the following to output a list of taxonomy terms with links showing only the current post type:
My remaining problem is that this still lists taxonomy terms that have no videos attached. E.g. maybe another post type has been given a ‘country’ tag of ‘Canada’. Even if there are no ‘videos’ tagged with ‘Canada’, ‘Canada’ will still show up in this list.