[wp-trac] [WordPress Trac] #11579: WordPress does not serialize properly multidimensional arrays in postmeta
WordPress Trac
wp-trac at lists.automattic.com
Wed Dec 23 16:52:14 UTC 2009
#11579: WordPress does not serialize properly multidimensional arrays in postmeta
---------------------------------------------------------------------------------------+
Reporter: ickatanet | Owner: westi
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Plugins | Version: 2.9
Severity: normal | Resolution: worksforme
Keywords: serialize, postmeta, array, multidimensional, save_post, update_post_meta |
---------------------------------------------------------------------------------------+
Changes (by westi):
* status: new => closed
* resolution: => worksforme
* milestone: Unassigned =>
Comment:
I've taken your code and tidied it up a bit so it doesn't cause php
warnings/notices when WP_DEBUG is enabled.
The following works fine for me:
{{{
/********************************************************************
ADD/EDIT POST VIEW */
add_action('admin_menu', 'o_add_custom_fields');
function o_add_custom_fields(){
add_meta_box( 'myplugin_sectionid', 'Additional Info',
'o_add_post_fields', 'post', 'advanced' );
}
function o_add_post_fields() {
global $post;
$data = get_post_meta($post->ID,'_post_data',true);
if ($data) {
$numbers = implode(',',$data['numbers']);
}
?>
<p>
<label for="numbers">Numbers <small>comma-
separated</small></label><br />
<textarea rows="4" cols="25" name="numbers" id="numbers"><?php
echo $numbers;?></textarea>
</p>
<?php
}
/********************************************************************
HANDLE POST REQUEST */
add_action('save_post', 'o_save_post');
function o_save_post($post_id) {
// update meta
if (isset($_POST['numbers'])) {
$explode = explode(',',$_POST['numbers']);
$map = array_map('trim',$explode); // prepare
$_post_data = array(
'numbers' => $map
);
update_post_meta($post_id, '_post_data', $_post_data);
}
}
}}}
Closing as Works for Me.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11579#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list