views:

39

answers:

1

While you can easily make a query result where vid=vocabularyId I'd like to know if there's a method in the api to do so so my code looks a bit less ugly. I'd like to know if theres something like vocabulary_get_nodes(vid) already implemented in Drupal's core.

+4  A: 

Not sure this is exactly what you want to do, but check out these three API functions:

  1. taxonomy_select_nodes()
  2. taxonomy_render_nodes()
  3. taxonomy_term_page()

If you search api.drupal.org, there are several other vocabulary related API functions as well, just search for the ones that begin with taxonomy_

bkildow
+1 for 'taxonomy_select_nodes()' - it should be added that this returns a query result resource, so one needs to add some code to extract the nodes: http://stackoverflow.com/questions/3050741/getting-an-array-of-nodes-related-to-a-category-term-with-the-drupal-api/3051161#3051161
Henrik Opel
Getting all terms and then aggregating the nodes seems to be the only way if the HAS to be used. I ended up querying the nodes myself.Thanks!
JoseMarmolejos
On Drupal 6 and 5, the query used by taxonomy_select_nodes() will use db_query_range() or pager_query(). If you really need to retrieve all nodes, you will need to call it multiple times, one for each results 'page'. pager_query() will user $_GET['page'] as page index and will store the number of pages in (global) $pager_total[0].Note that if the list of nodes is displayed on a page, paging is a good thing. In this case, simply uses a single call to taxonomy_select_nodes() and don't forget to include a pager on the rendered page (using theme_pager()).
mongolito404