function taxonomy_select_nodes

Return nodes attached to a term across all field instances.

This function requires taxonomy module to be maintaining its own tables, and will return an empty array if it is not. If using other field storage methods alternatives methods for listing terms will need to be used.


$tid: The term ID.

$pager: Boolean to indicate whether a pager should be used.

$limit: Integer. The maximum number of nodes to find. Set to FALSE for no limit.

$order: An array of fields and directions.

Return value

An array of nids matching the query.

2 calls to taxonomy_select_nodes()
taxonomy_term_feed in modules/taxonomy/
Generate the content feed for a taxonomy term.
taxonomy_term_page in modules/taxonomy/
Menu callback; displays all nodes associated with a term.


modules/taxonomy/taxonomy.module, line 204


function taxonomy_select_nodes($tid, $pager = TRUE, $limit = FALSE, $order = array(
    't.sticky' => 'DESC',
    't.created' => 'DESC',
)) {
    if (!variable_get('taxonomy_maintain_index_table', TRUE)) {
        return array();
    $query = db_select('taxonomy_index', 't');
    $query->condition('t.tid', $tid);
    if ($pager) {
        $count_query = clone $query;
        $query = $query->extend('PagerDefault');
        if ($limit !== FALSE) {
            $query = $query->limit($limit);
    else {
        if ($limit !== FALSE) {
            $query->range(0, $limit);
    $query->addField('t', 'nid');
    $query->addField('t', 'tid');
    foreach ($order as $field => $direction) {
        $query->orderBy($field, $direction);
        // ORDER BY fields need to be loaded too, assume they are in the form
        list($table_alias, $name) = explode('.', $field);
        $query->addField($table_alias, $name);
    return $query->execute()

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.