首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于自定义post分类ID的条件输出

基于自定义post分类ID的条件输出
EN

WordPress Development用户
提问于 2020-02-11 14:40:57
回答 1查看 127关注 0票数 0

我正在处理一个条件语句,要么只输出post缩略图,要么输出post缩略图和自定义post的链接。

输出基于检查post是否使用特定的分类法ID。

获取post的分类法ID不是问题,但是创建条件语句是个问题。

这是当前的代码:

代码语言:javascript
复制
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);的输出

代码语言:javascript
复制
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" } }

任何帮助我解决这个问题的建议都是非常感谢的。

使用该解决方案更新的代码:

代码语言:javascript
复制
$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;
}
EN

回答 1

WordPress Development用户

发布于 2020-02-11 15:00:21

将操作员改为:

代码语言:javascript
复制
 if($term->term_id === 4 ):

更多信息请查看这个:https://stackoverflow.com/a/80649/12785113

票数 -1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/358383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档