高级自定义字段:显示条件数据的多个复选框值

Advanced Custom Fields: multiple checkbox values displaying conditional data

我在 Wordpress 中使用高级自定义字段,并使用复选框字段根据所选内容显示数据。字段的 return 值设置为 'Value'.

我有两个复选框,我正在根据一个或另一个被选中来获取数据。但是是否可以在两个复选框都选中时显示数据?

例如:

<?php $options = get_field('options');?>
<?php if( $options && in_array('option-1', $options) ): ?>
  <p>Option 1 selected</p>
<?php elseif ( $options && in_array('option-2', $options) ): ?>
  <p>Option 2 selected</p>
<?php elseif ( $options && in_array('option-1', $options) && in_array('option-2', $options ): ?>
  <p>Option 1 and Option 2 selected</p>
<?php endif;?>

这可能吗?

是的,可以在上次 elseif 中使用 in_array_all 来选中两个复选框。

     <?php $options = get_field('options');
     $options = array($options); ?>
<?php if( $options && in_array(array('option-1','option-2'), $options)): ?>
     <p>Option 1 and Option 2 selected</p>
<?php elseif ( $options && in_array(array('option-2'), $options) ): ?>
  <p>Option 2 selected</p>
<?php elseif ($options && in_array(array('option-1'), $options) ): ?> 
 <p>Option 1 selected</p>
<?php endif;?>