Skip to content

Instantly share code, notes, and snippets.

@nguyenvanduocit
Created August 14, 2018 16:58
Show Gist options
  • Save nguyenvanduocit/4a1f6d45d9c025405274f11ca3007c77 to your computer and use it in GitHub Desktop.
Save nguyenvanduocit/4a1f6d45d9c025405274f11ca3007c77 to your computer and use it in GitHub Desktop.
function hcf_save( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$post_id = $parent_id;
}
$field_list = [
'hcf_author',
'hcf_published_date',
'hcf_price',
];
foreach ( $field_list as $fieldName ) {
if ( array_key_exists( $fieldName, $_POST ) ) {
update_post_meta(
$post_id,
$fieldName,
sanitize_text_field( $_POST[ $fieldName ] )
);
}
}
}
add_action( 'save_post', 'hcf_save' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment