I have a custom taxonomy called ‘locations’ which is being shared across a bunch of post types. I want to make a select field dropdown list of my locations (terms) to let users go to the taxonomy term page for each specific location; however I want to exclude some terms which are used in one post type and perhaps not in the others.
Is there a way to accomplish this?
I’m not a programmer so there’s probably a far more efficient/correct way of doing this.
Put this in functions.php or a custom plugin:
Usage examples:
<?php show_post_type_terms('taxonomy_name'); ?>
into custom post type archive template file to show a list of terms of taxonomy_name, excluding all terms that are not used by post of the current custom post type, and linking to a term archive which shows only post of that specific post type.<?php show_post_type_terms('taxonomy_name', 'custom_post_type_name'); ?>
in any other template file to do the same for a specific custom post type.[show_post_type_terms taxonomy="taxonomy_name" posttype="post_type_name"]
. Let me know if you’re looking for the code for this.Adapted from this. ($wpdb->prepare was changed to $wpdb->get_results because of this)