I found a error on weblinks.module about line 794

taxonomy_term_count_nodes don't exist on Drupal 7
I try to replace:

$term->node_count = taxonomy_term_count_nodes($tid, 'weblinks');

by:

       $term->node_count = db_query("SELECT COUNT(ti.nid) FROM {taxonomy_index} as ti INNER JOIN {node} as n on n.nid=ti.nid WHERE ti.tid = :aid and n.type='weblink'", array(':aid' => $tid) )->fetchField();

Comments

GStegemann’s picture

Status: Active » Fixed

Thanks.

This issue has been fixed in the current D7 development version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kumkum29’s picture

Issue summary: View changes

Hello,

is there a function to replace taxonomy_term_count_nodes in Drupal 7?
I have not found an alternative.

Thanks.

GStegemann’s picture

No, not really.

But I've written a replacement function in Web Links:

/*
 * Retrieve taxonomy node count by Term ID as by taxonomy_term_count_nodes.
 *
 * @param tid
 *   Term ID
 * @param type
 *   Node type
 * @param child_count
 *   TRUE - Also count all nodes in child terms (if they exists) - Default
 *   FALSE - Count only nodes related to Term ID
 */
function weblinks_term_node_count($tid, $type = '', $child_count = TRUE) {
  $tids = array($tid);

  if ($child_count){
    $tids = array_merge($tids, term_get_children_ids($tid));
  }

  global $language;
  $langs = array($language->language);
  $langs[] = 'und';

  $query = db_select('taxonomy_index', 't');
  $query->condition('tid', $tids, 'IN');
  $query->join('node', 'n', 't.nid = n.nid');
  $query->condition('n.status', 1, '=');
  if ($type <> '') {
    $query->condition('n.type', $type, '=');
  }
  $query->condition('n.language', $langs, 'IN');

  $count = $query->countQuery()->execute()->fetchField();
  return $count;
}
leopathu’s picture

Drupal 7 has another equivalent api to get taxonomy term's nodes. here is the api https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/funct...

It will return array value, we could count the array values with php.

<?php 
  $data = taxonomy_select_nodes($tid);
  $count = count($data);
fox mulder’s picture

I think taxonomy_select_nodes() is OK, but you must pay attention the second $pager param that is defaultly TRUE ( in my case this limited the result of count() function to 10 ) The correct code is:

  $data = taxonomy_select_nodes($tid, FALSE);
  $count = count($data);

See: https://api.drupal.org/comment/55993#comment-55993