【发布时间】:2022-01-10 14:36:49
【问题描述】:
嘿,我是新来的,听说了很多关于这个有用社区的信息。我正在尝试将我的自定义构建主题更新为 PHP 7.4,但在兼容性测试期间我发现了这个错误,我们将不胜感激。
我对 PHP 的了解为 0(目前)
这里是代码。
$type_terms = get_the_terms( $post->ID,"property-type" );
$type_count = count($type_terms);
if(!empty($type_terms)){
echo '<small> - ';
$loop_count = 1;
foreach($type_terms as $typ_trm){
echo $typ_trm->name;
if($loop_count < $type_count && $type_count > 1){
echo ', ';
}
$loop_count++;
}
echo '</small>';
}else{
echo ' ';
}
?>
</span>
</h5>
</div>
<div class="property-meta clearfix">
<?php
谢谢
【问题讨论】:
-
这意味着
get_the_terms返回了一个不是数组的值(例如NULL或false,或字符串)。可能,将$type_count = count($type_terms);移到下面一行(if下)可以解决问题 -
在这种情况下 $post 是什么?你得到什么?
-
使用
var_dump($some-variable);可能有助于调试。 -
谢谢大家从这里学到了很多关于 get_the_terms 的知识!问题已解决,感谢大家参与提问!
标签: php wordpress wordpress-theming php-7.3