Skip to content

Instantly share code, notes, and snippets.

@szbl
Created July 17, 2012 01:12
Show Gist options
  • Save szbl/3126273 to your computer and use it in GitHub Desktop.
Save szbl/3126273 to your computer and use it in GitHub Desktop.
Pulling Shared Taxonomy Terms Based On Single Post Type
I have three custom post types that share a hierarchical custom taxonomy for Location. Root level terms are states, child terms are cities.
These post types are different types of "records" for this site's many "directories" if you will. I'd like to be able to share the taxonomy across all three but do the following with a core function/query/whatever:
Example page:
/post-type-1/states/
Description:
Shows a listing of all states (root-level terms) that have been assigned to a post with the type "post-type-1"
Example page:
/post-type-2/states/
Description:
Shows a listing of all states (root-level terms) that have been assigned to a post with the type "post-type-2"
...and so forth...
I know I can wp_list_categories() or something of the sort to get all terms that are non-empty, but I ALSO want to filter by the post type applied.
Any thoughts? We're short on time/budget so I'm about to just allow city/state to be stored in a meta field so I can do a get_posts()/WP_Query call with a meta_query array.
I don't often as for help / advice, so thanks in advance!
@szbl
Copy link
Author

szbl commented Jul 17, 2012

Don't see get_posts_in_tax()......

@zanematthew
Copy link

Sorry, I was thinking of this: http://codex.wordpress.org/Function_Reference/get_posts (or you would use wp_query)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment