Support

Account

Home Forums General Issues Unable to set post status to future when setting future date via ACF field

Solved

Unable to set post status to future when setting future date via ACF field

  • Hi all, I’ve been struggling with this for days now.

    So I’m setting the post date of a custom post type based on an acf field, the dates will alway be in the future so I want the post to be “scheduled”. While the date does get properly set to the future https://share.getcloudapp.com/yAu9ylvN it’s still set at published even though I’m attempting to set post status to “future” it doesn’t do so. If I manually change the date in the WP date time picker the “update” button changes to a “Schedule” button and it works properly but for some reason setting it from an acf field doesn’t allow one to also set the post status to future. Code below.

    
    add_action("acf/save_post", "test_update_post_date_from_acf");
    function test_update_post_date_from_acf($post_id)
    {
      $post_date = get_field("start_date");
      $post = wp_update_post([
        "ID" => $post_id,
        "post_date" => $post_date,
        "post_status" => "future",
      ]);
    }
    
  • The only answer I can find is that you need to set both “post_date” and “post_date_gmt” when updating the post https://stackoverflow.com/questions/9740823/scheduling-a-post-in-wordpress-with-code-not-wordpress-backend

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.