Run Code After ACF Fields Are Saved

Use the acf/save_post action to execute custom logic after ACF fields are saved, with the correct priority to avoid common pitfalls.

php hooks
|

Use the acf/save_post action to execute custom logic after ACF fields are saved, with the correct priority to avoid common pitfalls.

Hook at priority 20 (above the default 10) to run after ACF has saved all field values:

<?php
add_action( 'acf/save_post', function ( $post_id ) {
    // Skip if this is an autosave, revision, or ACF options page save you don't want.
    if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
        return;
    }

    // Only run for a specific post type.
    if ( get_post_type( $post_id ) !== 'event' ) {
        return;
    }

    $date     = get_field( 'event_date', $post_id );
    $location = get_field( 'location', $post_id );

    // Example: send a notification when an event is updated.
    wp_mail(
        'team@example.com',
        'Event Updated: ' . get_the_title( $post_id ),
        sprintf( 'Date: %s | Location: %s', $date, $location )
    );
}, 20 );

Priority matters:

  • Priority < 10 — fires before ACF saves. get_field() returns the old values. Use $_POST['acf'] for new values.
  • Priority > 10 — fires after ACF saves. get_field() returns the new values. This is what you want most of the time.

Avoid infinite loops when using update_field() inside acf/save_post:

<?php
add_action( 'acf/save_post', function ( $post_id ) {
    if ( get_post_type( $post_id ) !== 'event' ) {
        return;
    }

    // Remove this action to prevent an infinite loop.
    remove_action( 'acf/save_post', __FUNCTION__, 20 );

    // Auto-generate a summary field from other fields.
    $date     = get_field( 'event_date', $post_id );
    $location = get_field( 'location', $post_id );
    update_field( 'summary', "{$date} — {$location}", $post_id );

    // Re-add the action for future saves.
    add_action( 'acf/save_post', __FUNCTION__, 20 );
}, 20 );

Related Snippets

Stay Updated

Get ACF tips and new extensions in your inbox

No spam. Unsubscribe anytime.