Support

Account

Home Forums ACF PRO ACF_Form – Default taxonomy via 'tax_input' without increasing permissions Reply To: ACF_Form – Default taxonomy via 'tax_input' without increasing permissions

  • Hi @ryandorn

    The acf/save_post hook will be executed everytime a post is saved. If you add an action in that hook, it will be executed after the post is saved. If you don’t know the concept of WordPress’ hook, here’s an article that explains it: http://wpcandy.com/teaches/how-to-use-wordpress-hooks/.

    You can execute the wp_set_object_terms() function in that hook, so the terms will be added automatically when you saved a post. It should be something like this:

    function my_acf_save_post( $post_id ) {
        
        // get the post object
        $the_post = get_post($post_id);
        
        // check if custom post type
        if( $the_post->post_type == 'my-cpt' ) {
            // add the term. Change 'true' to 'false' if you want to override it
            wp_set_object_terms( $post_id, 'my-term-slug', 'my-taxonomy-slug', true );
        }
        
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);

    I hope this makes sense 🙂