Support

Account

Home Forums Backend Issues (wp-admin) Hook after save

Solving

Hook after save

  • Hi.

    I have a custom post type with an ACF group and I need to update some data in the database after insert, update or delete the custom post.

    How is it better to do this, with the hook do_action(‘save_post_postype’ …) or with the filter add_filter(‘acf/pre_save_post’…)?

    Thanks for your help…

  • acf/pre_save_post only runs on the front end of the site for acf_form().

    The best hook to run after ACF saves data is acf/save_post with a priority > 10.

    But this will not work when deleting posts. For deleting posts you’ll need to rely on some WP hook, but I don’t know what that would be.

  • you’re right, acf/pre_save_post only runs on the front end.

    There are lots of WP hooks for this, but I’ve done tests and none covers all possibilities.

    Oddly enough, the only one that works really well is
    add_filter(‘post_updated_messages’,’ my_function’);

    This is triggered “always”, except in delete post, that have to use
    add_action(‘delete_post’, ‘codex_sync’, 10);

    I do not know if there is a better option

    Thanks for your help

  • acf/save_post is run on any page that has acf fields for either adding or updating a post. It is dependable, but like I said, is not called when deleting a post.

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

The topic ‘Hook after save’ is closed to new replies.