Support

Account

Home Forums ACF PRO acf_form 'acf/save_post' performance Reply To: acf_form 'acf/save_post' performance

  • Hi John,

    Thanks for this and thanks for the clarification. (also apologies for my delayed response).

    I’ve since updated my functions to reduce post_meta functions. However, I use acf_forms in multiple locations and I have them perform multi-relational actions (not just on the post_id itself, but rather ‘connected’ ones)…either way I’m rolling out functions to simplify this. Essentially, based on the page within which I embed an acf_form, I need acf/save_post to perform different actions without interfering with each other.

    My main question was if it was better (more performant) to use conditionals within one add_action hook or have multiple add_action hooks, i.e.

    
    function my_acf_save_post( $post_id ) {
        
        if($post_id = 1){
    	    // do something 1
        }
        if($post_id = 2){
    	    // do something 1
        }
        if($post_id = 3){
    	    // do something 1
        }
        if($post_id = 4){
    	    // do something 1
        } 
        
    }
    
    add_action('acf/save_post', 'my_acf_save_post', 20);
    

    vs.

    
    function my_acf_save_post_1( $post_id ) {
        
        // do something 1
    }
    
    add_action('acf/save_post', 'my_acf_save_post_1', 20);
    
    function my_acf_save_post_2( $post_id ) {
        
        // do something 2
    }
    
    add_action('acf/save_post', 'my_acf_save_post_2', 20);
    
    function my_acf_save_post_3( $post_id ) {
        
        // do something 3
    }
    
    add_action('acf/save_post', 'my_acf_save_post_3', 20);
    
    function my_acf_save_post_4( $post_id ) {
        
        // do something 4
    }
    
    add_action('acf/save_post', 'my_acf_save_post_4', 20);
    

    I personally prefer multiple ‘if’ functions because I’ve found that without that some forms seem to interfere with each other (I have a lot of them and sometimes multiple forms on the same page).