试试这段代码,它肯定会有用的,在测试这段代码之前,请确保您已经将类别标题添加为数字。
$terms = get_terms( array(
\'taxonomy\' => \'list\',
\'hide_empty\' => false
));
$user = wp_get_current_user();
if(!empty($terms)){
foreach ( $terms as $term ) {
if($term->name == $user->ID){
// Do something
}
}
}
此代码仅适用于您提供的id的帖子。
$args = array(\'orderby\' => \'name\', \'order\' => \'ASC\', \'fields\' => \'all\');
// You need to add Current Post ID here.
$get_terms = wp_get_post_terms($post_id,\'list\',$args);
//Get Current User Info
$user = wp_get_current_user();
//Check array is not empty
if(!empty($get_terms)){
foreach ( $get_terms as $term ) {
if($term->name == $user->ID){
// Do something
}
}
}