SO网友:Md. Ehsanul Haque Kanan
查看以下几行,了解如何添加自动保存功能:
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\' );
您可以找到有关自动保存功能的更多信息
right here.