我有一系列输入字段集:
<input type="text" name="people[name]" />
<input type="text" name="people[lastname]" />
<input type="text" name="people[email]" />
<input type="text" name="people[name]" />
<input type="text" name="people[lastname]" />
<input type="text" name="people[email]" />
...
我正在寻找一种将值存储为如下数组的方法{ people: { name: xxx , lastname: yyy, email: zzz }, { name: xxx , lastname: yyy, email: zzz }, { name: xxx , lastname: yyy, email: zzz }, ... }我将使用update\\u post\\u meta();保存值。
谢谢你的帮助。
编辑
// CALLBACK
<?php
function show_people_box($post){
$metas = json_decode(get_post_meta($post->ID,\'people\',true));
?>
<?php
$hiterms = get_terms(\'people\', array(\'orderby\' => \'slug\', \'parent\' => 0, \'hide_empty\' =>false));
?>
<?php foreach($hiterms as $key => $hiterm) { ?>
<h2 style="text-align:center;"><?php echo $hiterm->name; ?></h2>
<table width="100%">
<?php
$args = array(
\'post_type\'=>\'people\',
\'orderby\' => \'menu_order\',
\'post_parent\' => 0,
\'tax_query\' => array(array(
\'taxonomy\' => \'people\',
\'field\' => \'id\',
\'terms\' => $hiterm->term_id
)));
?>
<?php
$query = new WP_Query($args);
while($query->have_posts()){
$query->the_post();
?>
<?php
$children = get_children(array(\'post_type\' => \'people\', \'post_parent\' => get_the_ID() ));
if($children) {
?>
<tr>
<td><input name="people[name]" type="text" /></td>
<td><input name="people[lastname]" type="text" /></td>
<td><input name="people[email]" type="text" /></td>
</tr>
<?php
$args_2 = array( \'post_type\'=>\'people\',\'post_parent\' => get_the_ID() );
$query_2 = new WP_Query($args_2);
while($query_2->have_posts()){
$query_2->the_post();
?>
<tr>
<td><input name="people[name]" type="text" /></td>
<td><input name="people[lastname]" type="text" /></td>
<td><input name="people[email]" type="text" /></td>
</tr>
<?php
}
} else {
?>
<tr>
<td><input name="people[name]" type="text" /></td>
<td><input name="people[lastname]" type="text" /></td>
<td><input name="people[email]" type="text" /></td>
</tr>
<?php
}
?>
<?php
} wp_reset_postdata();
?>
</table>
<?php } ?>
<?php
}
// SAVE
add_action( \'save_post\', \'save_people_box\' );
function save_people_box(){
foreach($_POST[\'people\'] as $key => $value){
$peoples[$key] = $value;
}
global $post;
update_post_meta( $post->ID, \'people\', json_encode($peoples) );
}
我希望这能有所帮助,为了简化我的问题,我删除了一些html标记。再次感谢你的帮助。