Saturday, 24 August 2013

Updating post meta box and Meta Box plugin

Updating post meta box and Meta Box plugin

I've installed Meta Box wordpress plugin and create a text field meta box
with clone option:
add_action( 'admin_init', 'rw_register_meta_boxes' );
function rw_register_meta_boxes()
{
$meta_boxes = array();
$meta_boxes[] = array(
'id' => 'vip',
'title' => 'VIP Links',
'pages' => array( 'post'),
'fields' => array(
array(
'name' => 'Download links',
'id' => "vip",
'desc' => 'Type here',
'type' => 'text',
'std' => '',
'size' => 100,
'clone' => true,
),
),
'validation' => array(
'rules' => array(
"vip" => array(
'required' => false,
),
)
)
);
foreach ( $meta_boxes as $meta_box )
{
new RW_Meta_Box( $meta_box );
}
}
it works and meta box is added. But the problem is that, I need to do some
works on values while post publishing and then update the meta box values:
$VIP = get_post_meta($pid, 'vip', false);
/*
do some operations here
*/
update_post_meta($pid, 'vip', $NEW_VIP);
This snippet is within a function that's called on post publish:
add_action('publish_post', 'function_name');
But It won't update! I tried to see if function runs and which values
$NEW_VIP contains. So I added a line before update_post_meta() function to
assure myself:
print_r($NEW_VIP); die();
Output is as expected and $NEW_VIP has correct values (is an array) but
update_post_meta doesn't save it and meta box value(s) will always remain
unchangeable.
Any help would really be appreciated.

No comments:

Post a Comment