好吧,我终于自己解决了这个问题。这是因为:
创建第一个字段:
<?php
while($mb->have_fields_and_multi(\'types\')):
$mb->the_group_open();
$mb->the_field(\'type\');
?>
<input type="text" id="<?php $mb->the_name(); ?>" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" />
<a href="#" class="dodelete button">Remove</a>
<?php
$mb->the_group_close();
endwhile;
?>
<a href="#" class="docopy-types button" style="float: left">Add new</a>
<a href="#" class="dodelete-types button" style="float: right">Delete all</a>
使用时创建第二批字段
foreach
从第一个字段获取数据并将其放入
select
:
<?php
while($mb->have_fields_and_multi(\'details\')):
$mb->the_group_open();
$mb->the_field(\'detail_select\');
?>
<select name="<?php $mb->the_name(); ?>">
<option value="">Choose...</option>
<?php foreach ($meta[\'types\'] as $types) { ?>
<option value="<?php echo $types[\'type\']; ?>"<?php $mb->the_select_state($types[\'type\']); ?>><?php echo $types[\'type\']; ?></option>
<?php } ?>
</select>
<?php $mb->the_field(\'detail_title\'); ?>
<label>Description</label>
<input type="text" id="<?php $mb->the_name(); ?>" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>" /><br />
<a href="#" class="dodelete button">Remove</a>
<?php
$mb->the_group_close();
endwhile;
?>
<a href="#" class="docopy-estate_details button">Add new</a>
<a href="#" class="dodelete-estate_details button">Delete all</a>