Find a term ID (working around the category module) to have a node behave differently
find out what category vocabulary id drupal
probably easiest just to look in the database-- the vocabulary table lists names with vids, you can then go to the term_data table and sort by vocabulary if necessary, and look up your category by name.
Other option is to print_r everything about the category node.
For more, see:
http://drupal.org/node/113651
Resolution
We did it our way. Here's the messy, just-got-it-working
/**
* This function takes a node object and a term ID and returns true if the node
* has that term.
*
* @param node
* A node object.
* @param tid
* A term ID.
*/
function zing_auction_node_has_term($node, $tid) {
// @TODO: could this be done faster with an array_keys?
// and we should also allow 'tid' to be an array of tids
// print node if a submin
global $user;
if (in_array('submin', $user->roles)) { ?>
<pre><?php print_r($node); ?></pre>
<?php
}
/*
Category module seems to break this:
$terms = taxonomy_node_get_terms($node);
foreach(terms as $term) {
if ($term->tid == $tid) return TRUE;
}
*/
// so we'll follow our TODO suggestion
$node_tids = array_keys($node->taxonomy);
if (in_array($tid, $node_tids)) {
return TRUE;
}
return FALSE;
}
And the shiny, straightforward version of the function:
/**
* This function takes a node object and a term ID and returns true if the node
* has that term.
*
* This is widely useful and could be a candidate for taxonomy core or a
* utility module of some sort.
*
* @param node
* A node object.
* @param tid
* A term ID.
*/
function zing_auction_node_has_term($node, $tid) {
// @TODO: allow 'tid' to be an array of tids
$node_tids = array_keys($node->taxonomy);
if (in_array($tid, $node_tids)) {
return TRUE;
}
return FALSE;
}
Comments
Post new comment