Wordpress - 获取部分分类名称
Wordpress - Get part of taxonomy name
可以帮我吗?
我正在尝试将名称的一部分用于分类。
分类学 slug:temporada-01
我只需要号码:01
我有这个代码,但是显示的是名字。
<?php
$terms = get_the_terms( $post->ID , 'temporada' );
if ( $terms != null ){
foreach( $terms as $term ) {
print $term->name;
unset($term);
}
}
?>
如何检索名字的一部分?
谢谢。
尝试 get_term_by('id', $post->ID, 'taxonomy_name')
http://codex.wordpress.org/Function_Reference/get_term_by
试试只保留数字的 preg_replace() 函数:
print preg_replace( '/[^0-9]/', '', $term->name );
可以帮我吗?
我正在尝试将名称的一部分用于分类。
分类学 slug:temporada-01
我只需要号码:01
我有这个代码,但是显示的是名字。
<?php
$terms = get_the_terms( $post->ID , 'temporada' );
if ( $terms != null ){
foreach( $terms as $term ) {
print $term->name;
unset($term);
}
}
?>
如何检索名字的一部分?
谢谢。
尝试 get_term_by('id', $post->ID, 'taxonomy_name') http://codex.wordpress.org/Function_Reference/get_term_by
试试只保留数字的 preg_replace() 函数:
print preg_replace( '/[^0-9]/', '', $term->name );