Created
February 3, 2015 03:43
-
-
Save mrbobbybryant/2a291eece8f65e54f1d1 to your computer and use it in GitHub Desktop.
WordPress Custom Fields Saving function
This file contains 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
<?php function dwwp_meta_save( $post_id ) { | |
// Checks save status | |
$is_autosave = wp_is_post_autosave( $post_id ); | |
$is_revision = wp_is_post_revision( $post_id ); | |
$is_valid_nonce = ( isset( $_POST[ 'dwwp_jobs_nonce' ] ) && wp_verify_nonce( $_POST[ 'dwwp_jobs_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false'; | |
// Exits script depending on save status | |
if ( $is_autosave || $is_revision || !$is_valid_nonce ) { | |
return; | |
} | |
if ( isset( $_POST[ 'job_id' ] ) ) { | |
update_post_meta( $post_id, 'job_id', sanitize_text_field( $_POST[ 'job_id' ] ) ); | |
} | |
} | |
add_action( 'save_post', 'dwwp_meta_save' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment