Support

Account

Home Forums ACF PRO Prefilled Datepicker field with posts publish date

Unread

Prefilled Datepicker field with posts publish date

  • Hi,

    my datepicker field should only auto filled with the post publish date if nothing insert manually.

    Can anyone help me out?

    EDIT:
    OMG… No it’s workig. I put this code in my functions.php.

    For everyone who search for this:

    add_action( 'save_post', 'set_post_sortdate', 10,3 );
    function set_post_sortdate( $post_id, $post, $update ) {
        // Only want to set if this is a new post!
        if ( $update ){
            return;
        }
    
        // Only set for post_type = post!
        if ( 'post' !== $post->post_type ) {
            return;
        }
    
        // Get the default term using the slug, its more portable!
        $sortdate = get_the_date('Y-m-d', $post_id);
    
        $field_key = "YOUR_FIELD_NAME";
        $value = $sortdate;
        update_field( $field_key, $value, $post_id );
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.