Home Forums Front-end Issues acf/save_post is not being triggered


acf/save_post is not being triggered

  • I have a front-end form on a page created with acf_form() that allows the user to upload an image. The form works perfectly; the image is uploaded, and the user meta custom field is updated. However, the function I call with the acf/save_post hook never gets executed. Even the error_log I added for testing never gets added to the error log, and no other errors are thrown, which makes me think the hook is not firing for some reason.

    I am using ACF Pro version 6.1.5

    Thanks in advance!

    $options = array(
       'id' => 'prescription-upload_form',
       'fields' => ['field_62212641db014'],
       'post_id' => 'user_' . $user_id,
       'form' => true,
       'uploader' => 'wp',
       'html_submit_button' => '<button type="submit" class="acf-button button button-primary button-large" value="Update Profile">Submit</button>',
    function my_acf_save_rx($post_id)
       error_log('post_id: ' . $post_id); // added to see if function gets called
       $prescription_img = get_field('upload_prescription', $post_id);
       delete_field('field_622242d3a3546', $post_id);
       delete_field('field_621f97b95de90', $post_id);
       delete_field('field_62213a21bab0a', $post_id);
       delete_field('field_62213a2bbab0b', $post_id);
       delete_field('field_62213a36bab0c', $post_id);
    add_action('acf/save_post', 'my_acf_save_rx', 20);
  • Given the code you have posted there is only one reason that I can think of that the hook is not firing and that is that the function is not in a file that is loaded during the submit process.

    Where is this function located?

  • all the code above is in the same file. I even tried moving the my_acf_save_rx() function to functions.php and it still didin’t work.

  • The template that is showing the page is not loaded during form submission It is only loaded when outputting content of the page. Your action filter must be in a file that is loaded on every page load, like functions.php

  • Thanks for your response.

    The file isn’t a template file, and it does get loaded on every page. Even still, as I said in my previous post, I added the action and callback functions to functions.php, and it still didn’t get called.

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

You must be logged in to reply to this topic.