【问题标题】:Blank with foreach() argument must be of type array | object, string given in带有 foreach() 参数的空白必须是数组类型 |对象,字符串
【发布时间】:2022-06-28 05:17:09
【问题描述】:
<?php $wheretowatch = get_field('wheretowatch'); ?>
<?php foreach($wheretowatch as $wheretowatch):?>
    <div class="movies-series-tvshow-wheretowatch">
            <div class="movies-series-tvshow-wheretowatch-thumbnail">
            <a href="<?php echo get_page_link($wheretowatch->ID);?>"> <img src="<?php echo get_the_post_thumbnail_url($wheretowatch->ID, 'thumbnail');?>"></a>
            </div>
        
            <div class="movies-series-tvshow-wheretowatch-title">
            <a href="<?php echo get_page_link($wheretowatch->ID);?>"><h6><?php echo $wheretowatch->post_title;?></h6></a>
            </div>
    </div>
<?php endforeach;?> 

没有在关系字段中输入值时出现错误是否有错误当条件不满足时如何给出回显?

【问题讨论】:

标签: wordpress advanced-custom-fields


【解决方案1】:

您可以检查该字段是否为空,如果有值则仅循环。

$wheretowatch = get_field('wheretowatch');

if (!empty($wheretowatch)):
    foreach (...) {}
else:
    echo 'your message';
endif;

【讨论】:

    猜你喜欢
    • 2022-12-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2021-04-28
    • 2021-06-02
    • 2020-06-20
    • 2019-10-10
    • 1970-01-01
    相关资源
    最近更新 更多