acf/validate_save_post


目录

Description

Fires when validating the $_POST data of a submitted form.

Used to add or remove validation errors controlling whether or not the submitted data will be saved.

Please note this is a generic action. If you are looking to validate a specific field value, please use the acf/validate_value filter instead.

Changelog

Example

This example demonstrates how to bypass validation for an administrator, and also to require a custom input value. See the Notes section below for additional information on the functions used.

functions.php

add_action('acf/validate_save_post', 'my_acf_validate_save_post');
function my_acf_validate_save_post() {

    // Remove all errors if the user is an administrator.
    if( current_user_can('manage_options') ) {
        acf_reset_validation_errors();
    }

    // Require custom input value.
    if( empty($_POST[‘acf’][‘field_xxxxxx’] ) ) {
        acf_add_validation_error( 'acf[field_xxxxxx]', 'Please check this input to proceed' );
    }
}

Notes

Additional functions

The following additional functions are made available during this action.


版本号 #1
由 壳壳虫 创建于 2026-08-29 15:44:03 UTC
由 壳壳虫 更新于 2026-08-29 15:44:03 UTC