Created
January 3, 2013 19:19
-
-
Save WagnerMatos/4446185 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the Data | |
function page_save_custom_meta($post_id) { | |
global $page_custom_meta_fields; | |
// verify nonce | |
if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) | |
return $post_id; | |
// check autosave | |
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) | |
return $post_id; | |
// check permissions | |
if ('page' == $_POST['post_type']) { | |
if (!current_user_can('edit_page', $post_id)) | |
return $post_id; | |
} elseif (!current_user_can('edit_post', $post_id)) { | |
return $post_id; | |
} | |
// loop through fields and save the data | |
foreach ($page_custom_meta_fields as $field) { | |
if($field['type'] == 'tax_select') continue; | |
$old = get_post_meta($post_id, $field['id'], true); | |
$new = $_POST[$field['id']]; | |
if ($new && $new != $old) { | |
update_post_meta($post_id, $field['id'], $new); | |
} elseif ('' == $new && $old) { | |
delete_post_meta($post_id, $field['id'], $old); | |
} | |
} // end foreach | |
} | |
add_action('save_post', 'page_save_custom_meta'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment