【发布时间】:2016-11-04 13:46:31
【问题描述】:
以下代码突然开始出现此错误:
<?php foreach (get_the_terms(get_the_ID(), 'loan-club') as $cat) : ?>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" title="ON LOAN AT: <?php echo $cat->name; ?>" />
<?php endforeach; ?>
有时分类法“loan-club”是空的。这可能是问题吗?如果是这样,有人可以指出正确的代码吗?
【问题讨论】:
-
检查这个函数的返回类型应该是数组还是对象 get_the_terms(get_the_ID(), 'loan-club')
-
"有时分类法 'loan-club' 是空的"。这就是问题。使用 if(is_array(get_the_terms(get_the_ID(), 'loan-club')))