Display a list of nodes that belong to several terms (eg term 1 and 2)

Last modified: October 5, 2006 - 14:03

The following code uses the taxonomy api to render a listing of nodes that belong to terms to more than one category. For example, if i have two taxonomies

  • shape
    • square (1)
    • circle (2)
  • colour
    • red (3)
    • blue (4)

(term ids are in brackets) the following code would return a list of nodes classified as blue squares:

  $myNodes = taxonomy_select_nodes(array(4,1),"and");
  print taxonomy_render_nodes($myNodes);

This can be modified to a list of all blue shapes and squares by changing the "and" to "or":

  $myNodes = taxonomy_select_nodes(array(4,1),"or");
  print taxonomy_render_nodes($myNodes);

 
 

Drupal is a registered trademark of Dries Buytaert.