0

How do I simply grab the taxonomy of a post using the post id? I have tried using the_terms and such but everything seems to require you know the taxonomy ahead of time.

2
  • Chances are there is no "the" taxonomy for a post. There are several. Are you trying to get a list of all of them? What? It isn't entirely clear what you want.
    – s_ha_dum
    Apr 25 '14 at 14:09
  • All I need is to find the taxonomy(ies) of post of a custom post type. It can output in any look or format and I can make it work.
    – campatsky
    Apr 25 '14 at 14:18
2

All I need is to find the taxonomy(ies) of post of a custom post type. It can output in any look or format and I can make it work

That being the case, what you need is get_object_taxonomies()

$taxonomies = get_object_taxonomies( 'post', 'objects' );

That will not give you the terms in the taxonomies. You will need to loop over $taxonomies and pull the terms out, if that is what you are trying to do. For example:

$taxonomies = get_object_taxonomies( 'post', 'objects' );
foreach ($taxonomies as $tax) {
  var_dump(get_the_terms(1,$tax->name));
}
1
$post_terms = wp_get_post_terms($post_id, 'your_term');

http://codex.wordpress.org/Function_Reference/wp_get_post_terms

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.