Community

inconsistent results when counting nodes with a given term ID

I've created a simple block in a D6 site that is designed to do nothing more than present the total number of nodes of a given content type that are tagged with a specific taxonomy term.
The code in the block is:

<?php

//term "rural" / tid=226
$term->tid = 226;

$count = taxonomy_term_count_nodes($term->tid, 'shop_profile');
print
$count;
?>

where 'shop_profile' is the content type I'm interested in (the term is only available to be used for this content type).

The block gives the correct result (285) for logged in users, but gives a different count (321) for unauthenticated users. The content type is visible to non-logged in users.

I'm very much a PHP novice, and would welcome some help to understand what's going on here and to fix it so that the results are consistent and accurate for all users.

Thanks
Graham

Comments

clear the cache

As the results for taxonomy_term_count_nodes are statically cached you'll get different results for logged in user and unauthenticated users. Clear the cache and you'll see same results for both kinds of users.

--
I am a PHP programmer. moving to become drupal programmer

Thanks for the tip. I've

Thanks for the tip.

I've cleared the cache several times, but I'm still seeing the same issue.

Maybe I'm missing something? Using admin menu I've cleared all caches. Also emptied the cache via the performance page. I've also looked at the db with phpmyadmin and truncated some cache tables in the hope that this might resolve the issue. All to no avail. Any other options?