User login

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;
}

Searched words: 
if a node is tagged with a term drupal if a node is in a category

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.