Support

Account

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

Solved

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);
    • Elliot

    • October 22, 2013 at 4:04 pm

    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:
    http://www.advancedcustomfields.com/resources/actions/acfsave_post/

    Thanks
    E

  • 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( 'davisshaver@gmail.com', 'Action run', 'ok' );
    }
    add_action('acf/save_post','dfm_hook_test', 20);
    • Elliot

    • October 23, 2013 at 5:29 pm

    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

    Thanks
    E

  • 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 :).

    • Elliot

    • October 24, 2013 at 3:40 pm

    Hi @davisshaver

    Please do!
    You can signup over here and get access to all the files!
    http://support.advancedcustomfields.com/forums/topic/become-a-beta-tester/

    Thanks
    E

  • 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);

    and

    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 ) )
    			return;
    
    		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.

    Thanks

    • Elliot

    • January 19, 2014 at 6:34 pm

    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
    E

  • 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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.