Support

Account

Home Forums General Issues Use Date/Time picker as post publication date Reply To: Use Date/Time picker as post publication date

  • Hi John
    Thanks for your reply.

    There were two posts I found on acf about setting publication post date using acf date/time picker on the fontend. Another post I’ve found on stackexchange.

    https://support.advancedcustomfields.com/forums/topic/set-post-publish-date-by-custom-field/

    https://support.advancedcustomfields.com/forums/topic/how-do-the-date-of-publication-by-a-front-end-form/

    https://wordpress.stackexchange.com/questions/219036/acf-field-to-set-publish-date-post-duplication-upon-update

    In any case – I have an acf form on the front end where the user creates a draft post. The form works fine and creates the draft post as required. However, I’d like to be able to include a date/time picker and have the selected date/time set as the post’s publication date. I tried using the following code but had no luck

    function my_acf_save_post( $post_id ) {
    	$acfDate = get_field('post_date', $post_id);
        //Test if you receive the data field correctly:
        //echo $acfDate;
        //exit (-1);
        $my_post = array();
        $my_post['ID'] = $post_id;
        $my_post['post_date'] = $acfDate;
        wp_update_post( $my_post );
    }
    add_action('acf/save_post', 'my_acf_save_post', 20);

    Any ideas?
    Thanks
    P