通过将term\\u name作为参数传递给过滤器的回调函数,解决了此问题。
function bn_term_title( $term_name ) {
$term_types = get_term_by( \'name\', $term_name, \'tax_1\' );
if( $term_types->taxonomy === \'tax_1\' ) {
if( get_locale() === \'bn_BD\' )
return get_term_meta( $term_types->term_id, \'tax1_bn\' );
else
return $term_name;
}
$term_categories = get_term_by( \'name\', $term_name, \'tax_2\' );
if( $term_categories->taxonomy === \'tax_2\' ) {
if( get_locale() === \'bn_BD\' )
return get_term_meta( $term_categories->term_id, \'tax2_bn\' );
else
return $term_name;
}
}
add_filter( \'single_term_title\', \'bn_term_title\' );
当
get_term_by()
将使
$taxonomy
参数可选。如果taxonomy参数变为可选,我们可以按以下方式执行:
function bn_term_title( $term_name ) {
$term_types = get_term_by( \'name\', $term_name );
if( get_locale() === \'bn_BD\' )
return get_term_meta( $term_types->term_id, \'term_bn\' );
else
return $term_name;
}
add_filter( \'single_term_title\', \'bn_term_title\' );