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:
<?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);
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.