• Resolved fnorte

    (@fnorte)


    Hello,

    I nhave a acf that is filter to be filled after a specific category is selected.
    I need to get this field data on wp save_post hook, I’d even try the wp_after_insert_post hook, booth withouth succes.

    Searching answers I’d find a lot of references to the ‘acf/save_post’ hook.
    I just try to get what data this hook have but with no success either.

    The code to test the acf/save_post hook on my functions.php theme file:

    function test_acf($post_id) {
       error_log( 'Saved post ID : ' . $post_id, false);
       error_log( var_export($_POST, true), false );
    
       //If you want to log what got saved to the database
       error_log( var_export(get_post($post_id), true), false );
    }
    add_action('acf/save_post', 'test_acf', 20);
Viewing 1 replies (of 1 total)
  • Hi there!

    ACF Support Team here, Thanks for reaching out with your query we would be happy to assist

    If you are trying to retrieve field data before saving the values in the database, you can replace the line below:

    add_action('acf/save_post', 'test_acf', 20);

    with:

    add_action('acf/save_post', 'my_acf_save_post', 5);

    The you can access the value using field key as shown below:

    $value=$_POST['acf']['field_abc123']

    Please check out our documentation at https://www.advancedcustomfields.com/resources/acf-save_post/#applied-before-save.

    If you need further clarification, please create a ticket using our ?support form and we can look into it further.

Viewing 1 replies (of 1 total)
  • The topic ‘get_fields in the save_post hook’ is closed to new replies.