Community & Support

SOLVED: get an array of nodes ordered by their vocabularyterm

Where can i find a description of the structure of the vocabulary object?

I want to get an array of nodes ordered by their vocabularyterm (all nodes have 1 term of the vocabulary) :

<?php array ( Vocabulary_term1 => array( node1_nid, node2_nid), Vocabulary_term2 => array( node3_nid, node4_nid, node5_nid), ...) ?>

first i load the vocabulary object:
<?php $vocabulary = taxonomy_vocabulary_load(1); //1 is the vocabulary vid ?>

Now i want to loop all terms:

<?php
$nodes_array
= array();
foreach (
$vocabulary->tids as $tid) { // !! $vocabulary->tids is just a guess !!
   
$nodes_array[$tid]=array();
    while (
$result = taxonomy_select_nodes($tid)) {
             
$nodes_array[$tid][] = $result->nid; // !! how do i get the nid from the result?  !!
}
?>

EDIT i've done some php coding to get the keys of the vocabulary object:
vid name description help relations hierarchy multiple required tags module weight language nodes

there doesn't seem to be an array of terms in this object...

thanks!

Comments

SOLVED WITH QUERIES

<?php
$vocabulary_vid
= 1;
$sql = "SELECT * FROM {term_data} WHERE vid = %d";
$query_terms = db_query(db_rewrite_sql($sql), $vocabulary_vid);
$sheet = array();
while (
$data = db_fetch_object($query_terms)){
 
$term = $data->name;
 
$tid = $data->tid;
// load all node nids belonging to the tid
   
$sql = "SELECT * FROM {term_node} INNER JOIN {node} ON term_node.nid=node.nid WHERE term_node.tid = %d AND ( node.tnid=node.nid OR node.tnid=0)"; //AND ( node.tnid=node.nid OR node.tnid=0) makes sure you only return the nodes in the original translation(to avoid duplicates with translations)
   
$query_nodes = db_query(db_rewrite_sql($sql), $tid);
    while (
$nodes = db_fetch_object($query_nodes)){
       
$nid = $nodes->nid;
       
$sheet[$term][] = $nid;
    }
}
?>

thanks to Benjamin Lowenstein, Colingo Labs LLC : http://benl.com/node/20 for the code example

nobody click here