adding autosave feature to custom fields

admin2025-01-07  5

Does anyone know how to add autosave feature for advanced custom fields or add acf to the autosave event. I searched about it but I didn't find any solution.

thank you

Does anyone know how to add autosave feature for advanced custom fields or add acf to the autosave event. I searched about it but I didn't find any solution.

thank you

Share Improve this question asked Jan 20, 2019 at 6:34 kydroninkydronin 212 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Take a look at these lines to have an idea about adding the autosave feature:

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' );

You can find more information about the autosave feature right here.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736263377a885.html

最新回复(0)