function site_map_taxonomy_term_count_nodes in Site map 8
Same name and namespace in other branches
- 7 site_map.module \site_map_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 site_map_taxonomy_term_count_nodes()
- SiteMapHelper::getTaxonomyTree in src/
SiteMapHelper.php - Render the taxonomy tree.
File
- ./
site_map.module, line 470 - Provides a site map functionality.
Code
function site_map_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];
}