Support » How-To and Troubleshooting » [Resolved] `wp_get_post_categories` equivalent for custom taxonomies?

[Resolved] `wp_get_post_categories` equivalent for custom taxonomies?

Viewing 2 replies - 1 through 2 (of 2 total)
  • So I found out that by definition wp_get_POST_categories can only get POST categories not a custom post’s categories.

    I need to use get_the_terms instead

    $category = get_the_terms( $post->ID, 'custom-taxonomy-here' ); //////find custom taxonomy category name
    foreach ( $category as $cat){
    echo $cat->name;

    One step further…

    (I’m just a noob so if this is wrong please be kind and correct me)

    Using wp_get_post_categories($post->ID) on a custom post type page just doesn’t work because it’s not a POST, it’s a custom post. So I want to find an equivalent to make a plugin work with custom post types.

    This is on a regular POSTS page…

    $categories = wp_get_post_categories($post->ID);
    print_r ($categories);

    and outputs Array ( [0] => 1 )
    which is the same as

    $mycustomcategories = get_the_terms( $post->ID, 'my-custom-categories' );
    foreach( $mycustomcategories as $term ) {
    	$categories [0] = $term->term_taxonomy_id;
    	// Get rid of the other data stored in the object
    print_r ($categories);

    which outputs Array ( [0] => 3 ) on my CUSTOM POST TYPE page.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] `wp_get_post_categories` equivalent for custom taxonomies?’ is closed to new replies.
Skip to toolbar