Reply To: Taxonomies in attachments

Home Forums TurboCSV Support Taxonomies in attachments Reply To: Taxonomies in attachments


Hi Chris,

The code below inserted after the update/insert has been executed around line 280 in ti_import.php seems to work.
    //Special treatment for taxonomies associated with attachments
        $tax_input = $post[‘tax_input’];
$append = true; // append or replace taxonomy values

        if ( !empty($tax_input) && get_post_type($post_id)==’attachment’ ) {
            foreach ( $tax_input as $taxonomy => $tags ) {
                $taxonomy_obj = get_taxonomy($taxonomy);
                if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
                    $tags = array_filter($tags);
                if ( current_user_can($taxonomy_obj->cap->assign_terms) )
                    wp_set_post_terms( $post_id, $tags, $taxonomy, $append );
Incidentally, you might want to consider treating all taxonomy inserts/updates like this. wp_insert_post  does a full replace of taxonomy values. With wp_set_post_terms you can either replace or append values.  If you have the option of appending values, you can build up taxonomy structures incrementally. I expect that this would be a common use case when doing bulk loads.

I have also come to appreciate the elegance of your coding. It makes trouble shooting so much easier!