• I want to modify an ACF field when the post status changes to my custom post status called “Order Assigned”.

    I have verified that I’m using the correct field key, the function is running, and the IF statement is evaluating to true. However, the field is not updating, or perhaps it’s getting overwritten by something else.

    function ls_add_to_calendar($new_status, $old_status, $post) {
    
      if( $new_status != $old_status && $new_status == 'order-assigned' ) {
    
        update_field('field_561e9cbfdd5e6', '123', $post->id);
    
      }
    }
    
    add_action( 'transition_post_status', 'ls_add_to_calendar', 10, 3 );

    Any ideas as to why it’s not working? Thanks.

    https://www.ads-software.com/plugins/advanced-custom-fields/

Viewing 1 replies (of 1 total)
  • I tried to get update_field to work during transition_post_status, but never could. I ended up switching to using the built in post meta data by using the add_post_meta function.

    
    if ( $new_status == 'publish' && $old_status != 'publish' ) {
            add_post_meta($post->ID, '_mykey', '123, true);
            //update_field( "field_534dc7420db07", $value, $post->ID );
    }

    and then later when you want the value back:
    $mykey = get_post_meta( get_the_ID(), '_mykey', true );

Viewing 1 replies (of 1 total)
  • The topic ‘Using update_field() on post status transition?’ is closed to new replies.