Home Forums Backend Issues (wp-admin) Setting correct priority on publish_post action


Setting correct priority on publish_post action

  • Hi there – I am trying to add an action to the publish_post hook, but can’t figure out how to make it run after ACF fields are saved. Here is what my add action calls look like now. I can see that at time function runs, the updated data is not yet available. Any guidance appreciated.

    add_action('publish_post','dfm_publish_to_politics', 150);
    add_action('publish_future_post','dfm_publish_to_politics', 150);
  • Hi @davisshaver

    I believe that the publish action is run before the save action. ACF uses teh save action, so I don’t think any priority number will get your code to run after acf. Instead, you should use the save_post action.

    Better than that, you should use the acf/save_post action.
    You can read more about this here:


  • Thanks Elliot! Appreciate the help.

  • It appears that this action is running twice when I publish a post. I used th following code as diagnostic and received two emails. Any idea what’s going on?

    function dfm_hook_test() {
    wp_mail( '[email protected]', 'Action run', 'ok' );
    add_action('acf/save_post','dfm_hook_test', 20);
  • Hi @davisshaver

    WP always saves twice!

    The first time is for the revision, the second is for the real post. You can read up on this on the WP codex page for save_post


  • Didn’t realize that! I will use !wp_is_post_revision( $post_id ) to return out of the revision case. Thanks again.

    PS Looking forward to conditional logic in repeater box. Happy to beta test if you need someone :).

  • Hi @davisshaver

    Please do!
    You can signup over here and get access to all the files!


  • Thanks Elliot, just signed up. Looking forward to it.

  • Hi

    I am running into this exact issue. I tried the above suggestions but it seems that the email plugin does not hook into ‘acf/save_post’.

    This is what I have:

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


    public function process_subscriptions($post_id) {
    		$settings = incsub_sbe_get_settings();
    		// If this is just a revision, don't send the email.
    		if ( wp_is_post_revision( $post_id ) )
    		if(in_array(get_post_type($post_id), $settings['post_types']))
    			$this->send_mails( array( $post_id ) );

    Nothing happens, even if I put a exit code in the function, the WP still just goes through without ever calling this function.

    Any ideas? Again this is inside a plugin.


  • Hi @flagman5

    I can assure you that the acf/save_post is an action which is fired each time ACF saves data to a post.

    Perhaps you need to do some debugging in your code.


  • Thanks @elliot

    The way I solved it is to place the add_action and call to init the plugin from the theme’s functions.php and then use the above code to begin the email subscription process.

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

The topic ‘Setting correct priority on publish_post action’ is closed to new replies.