Php 来自ACF中组内组中字段的数据
我正在使用高级自定义字段来存储市议会选举产生的人的数据。 我在我的ACF插件中使用以下结构:Php 来自ACF中组内组中字段的数据,php,wordpress,while-loop,advanced-custom-fields,Php,Wordpress,While Loop,Advanced Custom Fields,我正在使用高级自定义字段来存储市议会选举产生的人的数据。 我在我的ACF插件中使用以下结构: 组别:Concil 第1分组:选举产生的第1分组 字段1:名称 字段2:名字 字段3:生日 字段4:职务 领域5:性别 第2分组:选举产生的第2分组 字段1:名称 字段2:名字 字段3:生日 字段4:职务 领域5:性别 [……] 小组69:当选小组69 字段1:名称 字段2:名字 字段3:生日 字段4:职务 领域5:性别 我可以在每个职位上选出多达69名候选人(但在大多数情况下较少)。 我试图在
- 第1分组:选举产生的第1分组
- 字段1:名称
- 字段2:名字
- 字段3:生日
- 字段4:职务
- 领域5:性别
- 第2分组:选举产生的第2分组
- 字段1:名称
- 字段2:名字
- 字段3:生日
- 字段4:职务
- 领域5:性别 [……]
- 小组69:当选小组69
- 字段1:名称
- 字段2:名字
- 字段3:生日
- 字段4:职务
- 领域5:性别
<?php
$gender = 'gender';
$name = 'name';
$firstname= 'firstname';
$birthdate = 'birthdate';
$jobtitle = 'jobtitle';
?>
<table class="table">
<thead>
<tr>
<th scope="col">Gender</th>
<th scope="col">Name</th>
<th scope="col">Birthday</th>
<th scope="col">Jobtitle</th>
</tr>
</thead>
<tbody>
<?php
for ($i=1; $i<=69; $i++){
if (have_rows('concil')) {
while (have_rows('concil')) {
the_row();} ?>
<?php
while (have_rows('elected_'.$i)) {
the_row();
${$gender.$i} = get_field('gender');
${$name.$i} = get_field('name');
${$firstname.$i} = get_field('firstname');
${$birtdate.$i} = get_field('birthdate');
${$jobtitle.$i} = get_field('jobtitle');
}?>
<tr>
<td><?php echo ${$gender.$i}; ?> </td>
<td><?php echo ${$name.$i}; ?> <?php echo ${$firstname.$i}; ?> </td>
<td><?php echo ${$birthday.$i}; ?></td>
<td><?php echo ${$jobtitle.$i}; ?></td>
</tr>
<?php }
}
?>
</body>
</table>
性别
名称
生日
职务
您知道为什么这段代码不起作用和/或有更好的解决方案在html表中显示这些数据吗?
谢谢你的帮助。
关于您是否尝试了
get_sub_field('gender')
而不是get_field('gender');
基本上-您使用的是嵌套中继器:-因此不需要$i
Hello Stender谢谢您的回复。我使用的不是中继器,而是文本字段。我的主要组字段(concil)有69个子组,它们都包含相同的文本字段(name/firstname/gender/等等)。我试图从get_字段更改get_sub_字段,但没有任何更改。(html表不显示)。。。