Add new input field in meta box
-
Hi guys!
I’m stuck…
What I’m trying to accomplish:
– I have created some metaboxes, and they work just fine. The problem is, I need a metabox, where I can add as many fields as I need – imagine like a shopping list – “add new item”….What have I already tried:
I’ve been following this guide – but without luck. I am able to CREATE the new “item” – but it doesent save it.This is what my “save” looks like:
function tr_save_meta($post_id, $post) { // Return user if he/she does not have the permission to do this! if(!current_user_can('edit_post', $post_id)) { return $post_id; } if(!isset($_POST['tr_items']) || !wp_verify_nonce($_POST['tr_items_nonce'], basename(__FILE__))) { return $post_id; } // Okay, we′re authorized - let′s save the data! $tr_meta['tr_items'] = esc_textarea($_POST['tr_items']); // Let′s cycle through the "$tr_meta" array foreach($tr_meta as $key => $value) : // Let′s not save the data twice if('revision' === $post->post_type) { return; } if(get_post_meta($post_id, $key, false)) { // If the field already has a value, we will update it... update_post_meta($post_id, $key, $value); } else { // If the field is empty, we will add the value add_post_meta($post_id, $key, $value); } // If there is no value, we will delete the meta key if(!$value) { delete_post_meta($post_id, $key); } endforeach; } add_action('save_post', 'tr_save_meta');
I’m confused…
What am I doing wrong?
Am I turning blind to my own code??Thanks in advance!
Aris Kuckovic
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Add new input field in meta box’ is closed to new replies.