Home › Forums › General Issues › update_field on Publish › Reply To: update_field on Publish
Hooking the acf/save_post
wont work, since every time the post is updated after it is published the acf/save_post
will trigger and replace the original $value
with a new $value
.
Consider $value being a unique timestamp that is run only once when the post transitions to the published state. $value = time();
If this is my functions.php, when the already Published post is updated field_534dc7420db07
gets a new value.
add_action('acf/save_post', 'my_acf_save_post', 20);
function my_acf_save_post( $post_id ){
$stat = get_post_status( $post_id );
$value = time();
update_field('field_534dc7420db07', $value, $post_id);
}
I can check the status of the post in my_acf_save_post, but only the current value, not if it is transitioning from pending to publish.
This is the reason I need to, and should, run the transition_post_status.
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.