You are here

function sitemap_taxonomy_term_count_nodes in Sitemap 8

Same name and namespace in other branches
  1. 8.2 sitemap.module \sitemap_taxonomy_term_count_nodes()
  2. 2.0.x sitemap.module \sitemap_taxonomy_term_count_nodes()

Count the number of published nodes classified by a term.

This is a re-implementation of taxonomy_term_count_nodes() that has been removed from D7 core.

Implementation note: the normal way to count field instances is through field_attach_query(), but taxonomy.module has a special denormalized table taxonomy_index which we can use for more speed. THX to taxonews.

Parameters

string $tid: The term's ID.

Return value

string An integer representing a number of nodes. Results are statically cached.

1 call to sitemap_taxonomy_term_count_nodes()
SitemapHelper::getTaxonomyTree in src/SitemapHelper.php
Render the taxonomy tree.

File

./sitemap.module, line 223
Provides sitemap functionality.

Code

function sitemap_taxonomy_term_count_nodes($tid) {
  $query = db_select('taxonomy_index', 'ti');
  $query
    ->addExpression('COUNT(ti.nid)');
  $count = $query
    ->condition('ti.tid', $tid)
    ->execute()
    ->fetchCol();
  return $count[0];
}