I have a metabox with an array of input:
<input type="text" name="activite_dates[]" size="30" /><br />
<input type="text" name="activite_dates[]" size="30" /><br />
<input type="text" name="activite_dates[]" size="30" /><br />
...
And i’m saving it like this
update_post_meta( $post_id, "dates", $_POST['activite_dates'] );
The problem is that when i’m retrieving it I have to make a ugly function to read multiple dimension array
Array
(
[0] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
)
[1] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
)
[2] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
)
)
And when I’m saving it, it’s only add to append to existent array
Array
(
[0] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
[4] => DATA1
[5] => DATA2
[6] => DATA3
[7] => DATA99
)
[1] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
[4] => DATA1
[5] => DATA2
[6] => DATA3
[7] => DATA99
)
[2] => Array
(
[0] => DATA1
[1] => DATA2
[2] => DATA3
[3] => DATA99
[4] => DATA1
[5] => DATA2
[6] => DATA3
[7] => DATA99
)
)
So first, why do I have 3 value at the first level then my array is multiplied inside of the second level ?
For information here is my code for the view :
$dates_gf = get_post_meta( $object->ID, 'dates', false );
foreach ($dates_gf as $date_gf) {
if (is_array($date_gf)){
foreach ($date_gf as $arr_date_gf) {
?> <input type="text" name="activite_dates_gf[]" value="<?php echo $arr_date_gf; ?>" size="30" /><br /> <?php
}
} else {
?> <input type="text" name="activite_dates_gf[]" value="<?php echo $date_gf; ?>" size="30" /><br /> <?php
}
} ?>
Thank you very much !
1 comment