Php ACF循环表复选框问题(WordPress)
我正忙于WordPress网站,并使用高级自定义字段插件。制作表格有问题,所以有正确或错误的选项。我将添加一个截图的结果,我到目前为止 以下是当前代码:Php ACF循环表复选框问题(WordPress),php,wordpress,checkbox,foreach,advanced-custom-fields,Php,Wordpress,Checkbox,Foreach,Advanced Custom Fields,我正忙于WordPress网站,并使用高级自定义字段插件。制作表格有问题,所以有正确或错误的选项。我将添加一个截图的结果,我到目前为止 以下是当前代码: <div id="abonnementen-table"> <table class="table table-hover"> <thead> <tr> <th>Specif
<div id="abonnementen-table">
<table class="table table-hover">
<thead>
<tr>
<th>Specificaties</th>
<?php foreach($abonnementen as $abonnement){?>
<th><?php echo $abonnement->post_title;?></th>
<?php }?>
</tr>
</thead>
<tbody>
<?php
$field = get_field_object('uitgebreide_specs',$abonnement->ID);
$choices = $field['choices'];
foreach ($choices as $choice_value => $choice_label){
?>
<tr>
<td><?php echo $choice_label;?></td>
<?php
foreach($abonnementen as $abonnement){
$values = get_field('uitgebreide_specs',$abonnement->ID);
$field = get_field_object('uitgebreide_specs',$abonnement->ID);
$choices = $field['choices'];
foreach ($values as $value) {
if ($value['value'] == $choice_value) {
echo '<td><i class="fas fa-check"></i></td>';
}
}
?>
<?php }?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
具体情况
问题在于上面的代码,如果选中该选项,它工作正常,但如果未选中该选项,则存在问题。屏幕截图将显示我的问题:
在这一点上,我试图提出另一种观点:
if ($value['value'] == $choice_value) {
echo '<td><i class="fas fa-check"></i></td>';
} else {
echo '<td></td>'; // unchecked
}
if($value['value']==$choice\u value){
回声';
}否则{
回显“”;//未选中
}
但是我有太多的专栏——见下面的截图。有人能告诉我我做错了什么吗
谢谢所以如果您能提供ACF字段的导出,我可以提供更好的答案。但是,添加未选中的
td
怎么样
$\u td=0;
foreach($value作为$value){
如果($value['value']=$choice\u值){
回声';
$_td++;
}
}
如果(!$\u td){//如果没有回显td,则添加它
回显“”;//未选中
}
或者使用array\u column()
$values=array_列($values,'value');
if(在数组中($choice\u value,$values)){
回声“Y”;
}否则{
回显“”;//未选中
}
我希望这些有帮助?介意分享$value和$choice吗?我认为每个循环都有一个太多的foreach循环,所以我认为将它们结合起来是一个不错的计划:)