I need to find a way to generate a csv export of a view such that a multi-term taxonomy field is developed into the generated csv as a single term in multiple columns.

I realise that developing a taxonomy in this way would generate a varying number of columns per row, but as long as the taxonomy is the last field in the view, this will not be a problem.

I've tried to intercept the relevant field at templating time in views-view-field.tpl.php (or specific equivalent for the taxonomy field in question) to see if it is possible to modify the output from "term1, term2" into "term1", "term2", but this doesn't work. I still get a single cell output with the modified contents.

I am now thinking it is not possible. Has anyone any other suggestions?

Cheers

Mike

Comments

Abelito’s picture

@peamik123, did you ever find a solution to this?
I'm looking for the same feature.

Cheers

Abelito’s picture

Ok, I came up with a solution that works for me because I dont need more than a few fields with terms.
1. add the views_customfield module.
2. in views add a new field of type Customfield: PHP code. (this will be your first term) put in this code:

<?php
$node = node_load($data->nid);
$terms = array_values(taxonomy_node_get_terms($node));
foreach ($terms as &$value) {
    if($value->vid=='8') {
        print $value->name;
        break;
    }
}
?>

3. add another Customfield:PHP code field. and enter this code:

<?php
$node = node_load($data->nid);
$terms = array_values(taxonomy_node_get_terms($node));
$i='1';
foreach ($terms as &$value) {
    if($value->vid=='8'){  /*vid is the taxonomy vocabulary id */
        if($i=='2'){  /*i equals the ordinal term you want */
            print $value->name;
            break;
        }
        else {
            $i++;
        }
    }
}
unset($value);
?>

4. continue as desired.

Abelito’s picture

FYI: Here is a way you can do it and limit the depth of the terms returned:

<?php /* Print the all terms with a depth of two or less for the taxonomy vocabulary I want if it has x parent term*/
$node = node_load($data->nid);
$terms = array_values(taxonomy_node_get_terms_by_vocabulary($node, '8')); /* the taxonomy vocabulary I want is 8*/
$lineages = array();
foreach ($terms as &$value) {
        $parents = taxonomy_get_parents_all($value->tid);
        $eldest = end($parents);
        if($eldest->tid=='323') { /* tid for the parent i want is 323*/

/* this part returns the term's hierarchical depth */
            $tid = $parents[0]->tid;
            $limit = 99;
            $depth = 1;
            while ($parent = db_result(db_query("SELECT parent FROM term_hierarchy WHERE tid=%d", $tid))) {
                $depth++;
                $tid = $parent;
                if ($depth > $limit) {
                    break;
                }
            }

            if($depth<=2){
                array_push($lineages,$parents[0]->name);
            }
        }
}
unset($value);
print implode('|',$lineages);

?>
neclimdul’s picture

Issue summary: View changes
Status: Active » Closed (outdated)