Support

Account

Home Forums General Issues Populate acf_form title with taxonomy term value Reply To: Populate acf_form title with taxonomy term value

  • Hey shanekins,

    You seem to be pretty close with this.. assuming that the dropdown you have created is returning the term ID, all you need to do is use the built in WordPress function ‘get_term’ to get the taxonomy’s name:

    
    
    function my_save_post( $post_id ) {
    
        // Pull the Term ID from the form:
        $term_id = $_POST['acf']['field_59940ffa4a644'];
    
        // Now get the WordPress term Object:
        $term = get_term( $term_id );
    
        // Check to see that a term is returned successfully
        if ( ! empty( $term && ! is_wp_error( $term ) ) )
        {
    
            // Now you can get the term name for your title
            $title = $term->name;
    
            $new_post = array(
                'ID'           => $post_id,
                'post_status' => 'publish',
                'post_title' => $title,
                'post_type' => 'points'
            );
    
            remove_action('acf/save_post', 'my_save_post', 20);
            wp_update_post( $new_post );
            add_action('acf/save_post', 'my_save_post', 20);
        }
    
    }
    
    add_action('acf/save_post', 'my_save_post', 20);