Advertising sustains the DA. Ads are hidden for members. Join today

Computed Field

CCK Taxonomy - accessing term names not just term ids

Last updated on
30 April 2025

This is a suggestion for another code snippet. If you try to pull the data from a CCK Taxonomy field, you get the Term ID and not the actual term name (the word or phrase or whatever the term is). Here's the code I put together to pull the actual term name.


$tid = $node->field_myfieldname[0]['value'];

$result = db_fetch_array(db_query("SELECT name FROM {term_data} WHERE tid = %d", $tid));

$node_field[0]['value'] = $result[name];

myfieldname - the name of your cck taxonomy field

I'm not a coder, so use this at your own risk.

Edit - with multiple terms:

$tids = $node->field_myfield;
foreach($tids as $key => $val)
{
$tid=$val[value];
$result = db_fetch_array(db_query("SELECT name FROM {term_data} WHERE tid = %d",$tid));
$node_field[]['value']=$result[name];
}

Help improve this page

Page status: Not set

You can: