0

I want to retrieve the category assigned to a custom post type.

The problem is, I don't know in advance what post-type (hence, what post-category) I will get. I have 5 custom post types, each with a custom taxonomy.

Can you point me in the right direction?

0

Blueprint

  1. Get all taxonomies.
  2. Loop through them.
  3. Get terms for current post.

Code

// Suppose you already have $post
foreach ( get_object_taxonomies( $post ) as $taxonomy ) {
    foreach ( get_the_terms( $post->ID, $taxonomy ) as $term ) {
        // Do whatever you'd like with $term
        echo $term->name;
    }
}

References

| improve this answer | |

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.