• We’re having issues with the acf/save_post hook not working after the recent 3.0 release and we’ve had to roll back to version 2.10.16.

    After updating the plugin, it seems as if it simply doesn’t fire when the form is submitted whereas previously it was working just fine. Is this a known issue or is there an alternative hook we can use instead? Essentially the function we’ve built hooks into the saved data via the frontend form and then processes it. This was working previously and looks like other users have used the acf/save_post approach in the past without any issues (i.e. https://wordpress.org/support/topic/how-to-use-shortcode-for-new-post-title/).

    Thanks in advance

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Shabti Kaplan

    (@shabti)

    Hello!

    Please replace acf/save_post with acf_frontend/save_post and in the function parameters replace ($post_id) with ($form, $post_id)

    Thread Starter cambridgeict

    (@cambridgeict)

    Hi Shabti

    Thanks for coming back to us. We’ve tried that but unfortunately we’re not having much joy with that updated hook. Just to make sure we’ve got it right, please see below example code.

    add_action( 'acf_frontend/save_post', 'custom_save_function', 10, 2 );
    
    function custom_save_function( $form, $post_id ) {
    	// Do something
    }

    We’ve added an error_log() line to our existing function to see if it’s firing but when submitting the frontend form we don’t get anything (form added using Elementor)

    Thanks in advance!

    Plugin Author Shabti Kaplan

    (@shabti)

    Are you adding/editing a post or a user

    Thread Starter cambridgeict

    (@cambridgeict)

    We’re updating an existing post. Essentially the function takes the data from the ACF frontend form and adds it programatically to an existing repeater. The custom function was working with no issues prior to version 3.0 using the acf/save_post hook.

    Thanks in advance

    I see this is resolved – can you share how you did it?

    I’m having the same/similar issue – multiple front-end forms via Elementor. The form appears to save, and it does indeed add newly uploaded the images to the Media Library, but it is not updating the actual post as intended.

    Thread Starter cambridgeict

    (@cambridgeict)

    @siteworkscollab – Yes, that’s exactly what we’re getting. We attempted the fix shared by @shabti but updating the acf/save_post hook to acf_frontend/save_post didn’t resolve our issue.

    @shabti – Are you able to provide a further update on this issue?

    Sorry to hijack this topic but I thought it might be related to the problem I’m having.

    The dev for Permalink manager wrote me this snippet when posts made through ACFFE forms did not adopt the custom permastructure.

    function pm_generate_uri_after_post_saved($post_id) {
        if(class_exists('Permalink_Manager_URI_Functions')) {
            $custom_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id, false, true);
            Permalink_Manager_URI_Functions::save_single_uri($post_id, $custom_uri, false, true);
        }
    }
    add_action('acf/save_post', 'pm_generate_uri_after_post_saved', 20);

    However it doesn’t work anymore and the permalink structure is only added when I update the post from the backend.

    I tried switching the acf/save_post to acf_frontend/save_post and it still didn’t work. I’m far from an expert on php though so maybe I missed something.

    I can confirm that the fix that @shabti posted and also sent to me in an email support thread doesn’t work for my issue either. Clearly that was not a solution

    same there, post type slug don´t change when edit post

    works if i delete text in slug field before update post in the form … this will be automatic when change post title.

    I make this with forms with acf extended and Permalink manager lite plugins and this works:

    `/*
    * @int $post_id The targeted post ID
    * @string $type Action type: ‘insert_post’ or ‘update_post’
    * @array $args The generated post arguments
    * @array $form The form settings
    * @string $action The action alias name
    *
    * Note: At this point the post & meta fields are already saved in the database
    */
    add_action(‘acfe/form/submit/post/form=editar_empresa’, ‘my_form_post_save’, 10, 5);
    function my_form_post_save($post_id, $type, $args, $form, $action){

    if(class_exists(‘Permalink_Manager_URI_Functions’)) {
    $custom_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id, false, true);
    Permalink_Manager_URI_Functions::save_single_uri($post_id, $custom_uri, false, true);
    }

    }
    `

    • This reply was modified 2 years, 8 months ago by sermalefico.
    • This reply was modified 2 years, 8 months ago by sermalefico.
    Plugin Author Shabti Kaplan

    (@shabti)

    Hey everyone. We wrote an article about the new version 3 action hook acf_frontend/save_post.

    It is a bit different from acf/save_post so be aware of these differences:

    • $post_id is the second of two parameters, so make sure to include both parameters and to set the fourth argument of add_action to “2”.
    • This hook is always fired after the fields have been saved so none of the fields will be in the $_POST global but rather with the $form[‘record’][‘post’] array.

    Here is the article: acf_frontend/save_post

    All the best!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘ACF acf/save_post hook not working after 3.0 update’ is closed to new replies.