Home › Forums › ACF PRO › Must update post twice to get values passed › Reply To: Must update post twice to get values passed
That’s what’s in my reply above.
The problem is that the update_value
fires before that value is saved to the database.
This means that when you do get_field
to get the value you are getting the value it was from the previous update. If it’s a new post then you get nothing, if you change the date you will get the previous date.
The hook passes the new value as $value
so you should be using that for the value to update the title
function my_acf_update_value( $value, $post_id, $field ) {
// ** change this line
$date = strtotime($value);
$formatted_date = date('d F Y', $date);
$new_title = $formatted_date;
// update post
$my_post = array(
'ID' => $post_id,
'post_title' => $new_title,
'post_type' => 'usa',
'post_name' => $new_slug
);
// Update the post into the database
wp_update_post( $my_post );
return $value;
}
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.