WordPress - 获取分类名称的一部分


Wordpress - Get part of taxonomy name

能帮我吗?

我正在尝试将部分名称用于分类法。

蛞蝓

分类:颞蛞蝓-01

我只需要号码:01

我有此代码,但这显示名称。

 <?php 
   $terms = get_the_terms( $post->ID , 'temporada' );
    if ( $terms != null ){
     foreach( $terms as $term ) {
        print $term->name;
        unset($term);
     } 
    } 
?>

如何检索部分名称?

谢谢。

尝试一个只保留数字的 preg_replace() 函数:

print preg_replace( '/[^0-9]/', '', $term->name );

尝试get_term_by('id', $post->ID, 'taxonomy_name')http://codex.wordpress.org/Function_Reference/get_term_by