简体   繁体   中英

get_the_category_by_id() for custom taxonomy

I have written code that uses get_the_category_by_id() - however I've now switched to use a custom taxonomy, and it no longer works.

Here is the code (please note that $settings->select_field is the ID of the particular category, ie 23 ):

$args = array('child_of' => $settings->select_field);
$catname = get_the_category_by_ID( $settings->select_field );

$catname = strtolower($catname);

$catname = str_replace(' ', '-', $catname);

$categories = get_categories( $args );
foreach($categories as $category) { 
    echo '<a class="sub-block block-' . $catname . '" href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
}

What is an alternative function I can use

这是我的解决方案:

$term = get_term( 23, 'video-category' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM