Home Forums General Issues Replace post_date by act date Reply To: Replace post_date by act date

  • Hi @pipoulito,

    Thanks for the post.

    I believe you can get the value of the date from the get_sub_field() function within the have_rows() loop and pass this to the ‘post_date’ argument of the wp_insert_post() within the acf/save_post action.

    The code would look like so:

    function my_acf_save_post( $post_id ) {
    // Create post object
    $my_post = array(
      'post_title'    => wp_strip_all_tags( $_POST['post_title'] ),
      'post_content'  => $_POST['post_content'],
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_date'     => $value //this can also be a normal date field value like so: $_POST['acf']['date_field_key']
    // Insert the post into the database
    wp_insert_post( $my_post );
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);