Support

Account

Home Forums General Issues Replace post_date by act date

Solved

Replace post_date by act date

  • HI,

    I’ve a repeater field “dates” with subfields date_event. (dates_0_date_event, dates_1_date_event)…

    Please, how to replace wp post date by dates_0_date_event when creating post or updating it ?

    something like this…
    if ($post_type=="event" && dates_0_date_event !="") wp postdate = dates_0_date_event;

    il faudrait donc que dates_0_date_event soit au même format que postdate

    THANKS !!!

    • James

    • June 6, 2016 at 7:44 pm

    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:

    <?php
    
    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);
    
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.