首页 > 解决方案 > 高级自定义字段组值为空,但包装元素仍然可见

问题描述

我正在使用Advanced Custom Fields. 所以现在我只想在它们“存在”时显示这些字段,例如如果它们有内容。我做了这个条件陈述:

$casemodule = get_field('case_page_instore');   

 if( $casemodule ) : ?>  
    <section class="block">
        <h2><?php echo $casemodule['case_header'] ?></h2>
        <p><?php echo $casemodule['case_subtext'] ?></p>
    </section>
<?php endif; ?>

太好了,如果字段case_headercase_subtext为空,它们将不会显示(显然),但或出于某种原因<section>-tag 始终可见,这有点奇怪,因为我按照ACF页面上的说明进行操作。

有人可以告诉我发生了什么吗?

更新

我试图这样做var_dump($casemodule),结果是:

array(2) { ["case_header"]=> string(0) "" ["case_subtext"]=> string(0) }

但这并没有解决任何问题

标签: phpwordpressadvanced-custom-fields

解决方案


我自己解决了,解决方法是:

if($casemodule['case_header'] && $casemodule['case_subtext']) : ?>

我只是删除了isset一个瞧!:-)

感谢 Reza 之前的回答


推荐阅读