Skip to content

Instantly share code, notes, and snippets.

@th3hamburgler
Created January 23, 2013 13:10
Show Gist options
  • Save th3hamburgler/4605395 to your computer and use it in GitHub Desktop.
Save th3hamburgler/4605395 to your computer and use it in GitHub Desktop.
Wordpress: Save data from post meta box. Ignore pesky revisions.
/**
* Save custom post data meta box
*
* @access function
* @param int
* @return void
*/
function save_post($post_id) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if (!wp_verify_nonce( $_POST['my_noncename'], MY_PLUGIN_DIRECTORY)) return;
// Check permissions
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) ) return;
} else {
if ( !current_user_can( 'edit_post', $post_id ) ) return;
}
if (get_post_type($post_id) == 'revision') return;
// save data
update_post_meta($post_id, 'my_value', $_POST['my_value']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment