WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] `wp_get_post_categories` equivalent for custom taxonomies? (3 posts)

  1. debsch
    Member
    Posted 2 years ago #

    I want exactly what this person in the post below wanted...

    http://wordpress.org/support/topic/wp_get_post_categories-equivelent-for-custom-taxonomies?replies=3
    "Does anybody know if there is an equivelent of wp_get_post_categories for a custom taxonomy? I only want ID's, not all the associated information."

    I thought I had found the answer...
    The post is marked as resolved.
    But the poster does not post up their solution.
    (Maybe they don't come from an open-source caring & sharing environment?)

    Can anyone help?

  2. debsch
    Member
    Posted 2 years ago #

    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;
    }
  3. debsch
    Member
    Posted 2 years ago #

    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
    	unset($term);
    }
    print_r ($categories);

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

    :)

Topic Closed

This topic has been closed to new replies.

About this Topic