Home › Forums › General Issues › update_field on Publish › Reply To: update_field on Publish
Hi,
I had a look at the transition_post_status
action on the codec, looks like it’s “not intended for use by plugin and theme developers”.
if you $value
is a static value I think what you want is pretty straight forward with ACF.
// run AFTER ACF saves the $_POST['fields'] data
// here we run the acf/save_post AFTER the data are saved and we update the field to your $value
add_action('acf/save_post', 'my_acf_save_post', 20);
function my_acf_save_post( $post_id ){
$value = "12345";
update_field('field_534dc7420db07', $new_tax, $post_id);
}
That way you ensure that the $value
stays always the same, it can be on newly published posts or on post that goes from pending to published, as soon as the post is saves the field_534dc7420db07
gets your value after it was saved.
you should leave the acf.php as it was and shouldn’t comment anything on that part it will end up breaking things.
then if you want to make more complicated stuff you can check if the post is published or pending or any other stuff using it’s id that is stored in $post_id
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.