php - 高级自定义字段组值为空,但包装元素仍然可见
问题描述
我正在使用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_header
和case_subtext
为空,它们将不会显示(显然),但或出于某种原因<section>
-tag 始终可见,这有点奇怪,因为我按照ACF页面上的说明进行操作。
有人可以告诉我发生了什么吗?
更新
我试图这样做var_dump($casemodule)
,结果是:
array(2) { ["case_header"]=> string(0) "" ["case_subtext"]=> string(0) }
但这并没有解决任何问题
解决方案
我自己解决了,解决方法是:
if($casemodule['case_header'] && $casemodule['case_subtext']) : ?>
我只是删除了isset
一个瞧!:-)
感谢 Reza 之前的回答
推荐阅读
- swift - 当我考虑锚点(0.5,0.5)时,为什么我的 SKSpriteNode 会移动这么远?
- python-3.x - Numba 正确实施?
- python-3.x - Python中连接坐标的排序列表
- firebase - 使用 Firebase Cloud Functions,我可以从外部 API 安排更新以更新 Firestore
- azure-devops - 如何将私有 nuget 源的凭据添加到 Azure DevOps Pipelines?
- javascript - 列表文本不会通过 Javascript 按钮更改颜色
- c - C函数替换参数的特定索引中的字节
- javascript - 如何在自定义选择组件标签上绑定 value 属性
- sharepoint - SharePoint 日期/时间计算决策树
- java - 集成测试休息控制器 assertEquals 失败