我正在处理一个条件语句,要么只输出post缩略图,要么输出post缩略图和自定义post的链接。
输出基于检查post是否使用特定的分类法ID。
获取post的分类法ID不是问题,但是创建条件语句是个问题。
这是当前的代码:
ID, 'my_taxonomy_name' );
// This if statement has to be incorrect
if($term->term_id == 4 ):?>
ID, 'full'); ?>
// It always returns the following
ID, 'full'); ?>这是var_dump($term);的输出
array(1) { [0]=> object(WP_Term)#10440 (10) { ["term_id"]=> int(4) ["name"]=>
string(4) "Case" ["slug"]=> string(4) "case" ["term_group"]=> int(0)
["term_taxonomy_id"]=> int(4) ["taxonomy"]=> string(16) "soort_referentie"
["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(2)
["filter"]=> string(3) "raw" } }任何帮助我解决这个问题的建议都是非常感谢的。
使用该解决方案更新的代码:
$terms = get_the_terms( $post_object->ID, 'my_taxonomy_name' );
foreach($terms as $term){;
if($term->term_id === 4 ):?>
ID, 'full'); ?>
ID, 'full');
break;
endif;
}发布于 2020-02-11 15:00:21
https://wordpress.stackexchange.com/questions/358383
复制相似问题