Howto do_action('function', $post->ID, $some, $args);
-
Hi everybody,
I’m trying to save data from my custom meta boxes, this can be one meta box, but also multiple. With the following code:
function image_attachments_init() { if($types = get_option('image_attachments_post_types')) { $fields = array(); foreach ($types as $type) { $image_size_name = get_option('image-size-name'); $image_size_slug = get_option('image-size-slug'); for($i = 0; $i <= count($image_size_name[$type]); $i++) { if($image_size_slug[$type][$i] != '' && $image_size_name[$type][$i] != '') { $settings[$image_size_slug[$type][$i]] = $image_size_name[$type][$i]; } } //E.G: $settings['test'] => 'test1', $settings['test2'] => 'test2' foreach($settings as $slug => $name) { $fields[] = $slug; add_meta_box($slug, $name, 'image_attachments_setup', $type, 'normal', 'high', array('slug' => $slug, 'name' => $name)); } } } //Must be executed once, right? Not in a loop... add_action('save_post','image_attachments_save', 5, 3); //Fields is now an array(2) { [0] => 'test1', [1] => 'test2' }, let's send them to image_attachments_save do_action_ref_array('save_post', $fields); } add_action('admin_init','image_attachments_init');
the ‘image_attachments_save’ function is the following
function image_attachments_save($fields) { global $post_id; echo $post_id; $post_id = $post->ID; /** * * The fields are defined in the function image_attachments_init(), so check if it's * array(2) { [0] => 'test1', [1] => 'test2' } * Ok, here we go, var_dump($fields); * Only gives string('test1') and int(788) and this is the post_id.... :confused:. * Just want to get array(2) { [0] => 'test1', [1] => 'test2' } */ var_dump(fields); return $post_id; }
If i’m doing a var_dump($fields) in image_attachments_save, i’m not getting the values in my $fields array.
How can this be done, and how can i get the new post id in the ‘image_attachments_save’ function.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Howto do_action('function', $post->ID, $some, $args);’ is closed to new replies.