Support

Account

Home Forums ACF PRO acf/save_post hook returning funny field names

Solved

acf/save_post hook returning funny field names

  • Hi,

    I am trying to get field values after an options page has been saved.

    For that I have copied the code from here:

    
    function my_acf_save_post( $post_id ) {
        
        // bail early if no ACF data
        if( empty($_POST['acf']) ) {
            return;
        }
        
        // array of field values
        $fields = $_POST['acf'];
    
        // specific field value
        $field = $_POST['acf']['kontingent_text'];
    }
    
    // run before ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 1);
    

    The field “kontingent_text” is a text field.

    However the field names returned are not the ones I enter in the field-editor.
    They are some kind of key…If I print the $fields variable, I get this:

    Array
    (
    [field_5516c5afed5e4] => Dies ist ein Kontingenttext!
    )

    The $field variable returns an undefined index error and only works if I insert field_5516c5afed5e4 as and index.

    Is there any way I can use the regular field names?

  • Hi @philex

    ACF uses the $field_key when submitting when submitting any form data so it may not be possible to use the $field_name

  • Ok, thanks for the information 🙂

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

The topic ‘acf/save_post hook returning funny field names’ is closed to new replies.