i’m working on the function that will allow the user to post/edit/manage posts from front end and i’m stuck with the array updating.
update_post_meta($post_id, 'lapp_appmenu',$_POST['appmenu']);
This method works for the single values but fails when dealing with Array(when submitted it just removes the previously setted value).
Thank you in advance,
Nikola
EDIT:
the array is a unlimited list of items.
<?php
$i = 0;
if ($appmenu) {
foreach($appmenu as $row) { ?>
<li><span class="sort hndle">|||</span>
<input type="text" name="lapp_appmenu[<?php echo $i; ?>]" id="lapp_appmenu" value="<?php echo $row; ?>" size="30" />
<a class="repeatable-remove button" href="#">-</a></li>
<?php
$i++;
}
} else { ?>
<li><span class="sort hndle">|||</span>
<input type="text" name="lapp_appmenu[<?php echo $i; ?>]" id="lapp_appmenu" value="" size="30" />
<a class="repeatable-remove button" href="#">-</a></li>
<?php }?>
WordPress stores the meta values as strings. When you pass
update_post_meta
an array, it automatically converts it to a string. What you’ll need to do isunserialize
it when you attempt to read the data.http://codex.wordpress.org/Function_Reference/update_post_meta (explains that the value is converted to a string)
http://php.net/manual/en/function.unserialize.php