Support

Account

Home Forums Backend Issues (wp-admin) save_post Action

Solved

save_post Action

  • I have some code that uses the WordPress save_post Action to manipulate data in a post type.

    I am copying the text from a post meta field into the post title and then calling wp_update_post().

    The title is never updated. If I disable ACF, the code works. It appears that my code is calling wp_update_post() and then ACF is calling wp_update_post() afterward and overwriting my update.

    I tried changing the priority to 99 and 999, but ACF is still overwriting any updates I do.

    This code fails every single time:

    add_action( 'save_post', 'am_save_post_handler', 999, 2 );
    function am_save_post_handler( $post_id, $post ) {
      update_field( 'client_contact_phone', '99 Boogie', $post_id );
    }

    client_contact_phone is a field managed by ACF and it never gets updated.

    This code works every single time:

    add_action( 'save_post', 'am_save_post_handler', 999, 2 );
    function am_save_post_handler( $post_id, $post ) {
      update_field( 'client_contact_phoneXX', '99 Boogie', $post_id );
    }

    client_contact_phoneXX is not managed by ACF, so it gets updated.

  • Never mind, changing the whole thing over to use acf/save with a priority of 20 fixed my problem.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘save_post Action’ is closed to new replies.