Your Location is: Home > Advanced-custom-fields

acf/save_post not triggered until manual update

From: France View: 4478 RichardU 


I'm using acf_form to create a post like this:

    <?php acf_form(array(
        'post_id'       => 'new_post',
        'post_title' => true,
        'new_post'      => array(
            'post_type'     => 'books',
            'post_status'   => 'publish'
        'fields' => array('field_5fb2a66de25ba', 'field_5fb009504f235',), 
        'submit_value'  => 'Create Book',
        'html_submit_button'  => '<input type="submit" value="%s" />',
        'updated_message' => ("Book submitted",)

Everything works except my acf/save_post function does not trigger until I manually edit the post and update it. Here's what I'm doing in acf/save_post:

            $key_word = get_field('field_5fb2a66de25ba', $post_id);
            update_post_meta( $post_id, 'rank_math_focus_keyword', $key_word );

This works, but not until I manually edit and update the page.

I'm not the only one with this question. If I get an answer, I'll find the others and share the good news.

Cheers, Richard

Best answer

Eureka! All I had to do was change the priority on my action:

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