wordpress, get category names for a custom post type

前端 未结 3 371
-上瘾入骨i
-上瘾入骨i 2021-01-15 03:20

Is there a better way to get the category names for a custom post type in wordpress?



        
3条回答
  •  情深已故
    2021-01-15 04:17

    
        
    
    

    Or in fuctions.php place this:

      function get_the_category_custompost( $id = false, $tcat = 'category' ) {
        $categories = get_the_terms( $id, $tcat );
        if ( ! $categories )
            $categories = array();
    
        $categories = array_values( $categories );
    
        foreach ( array_keys( $categories ) as $key ) {
            _make_cat_compat( $categories[$key] );
        }
    
        return apply_filters( 'get_the_categories', $categories );
    }
    

    and call the function as:

    ID, 'Your Custom Taxonomy'); ?>
    

提交回复
热议问题