Filtering nodes shown on taxonomy menu block As in the picture, the taxonomy terms are showing count of nodes tagged with the term( using taxonomy_menu module). That nodes are of type classified ads.

Is it possible to filter out expired ads ? I mean in the picture, the first menu item is "10th" with 24 nodes in it. But I want to filter out 5 nodes which have expired containing a hidden flag that it has expired. So that is should show as "10th(19)"

How can I do it?

Looks like in the file taxonomy_menu.database.inc we have this function:

function _taxonomy_menu_term_count($tid) {
  $result = db_select('taxonomy_index', 'tn');
  $result-&gt;condition('tid', $tid);
  $result-&gt;join('node', 'n', 'n.nid = tn.nid AND n.status = 1');
  $result-&gt;addExpression('COUNT(n.nid)', 'term_count');
  $temp = $result-&gt;execute();
  $temp = $temp-&gt;fetchObject();
  return $temp-&gt;term_count;
}


Along with n.status I should add n.field_expired check to exclude I think.  I wouldn't mind to temporarily hack the code of Taxonomy Menu though.
Since you said you "would not mind temporarily touching the code" (I would highly advise not to touch and try to find alternative ways) here is my quick solution and also alternative ways of accomplishing it.

Assuming the field_expired is a boolean field (single on/off check-box values 1/0) and you are not using revisioning.(see the three lines I added), also make sure you resave at least one node to recalculate.

function _taxonomy_menu_term_count($tid) {
  $result = db_select('taxonomy_index', 'tn');
  $result-&gt;condition('tid', $tid);
  $result-&gt;join('node', 'n', 'n.nid = tn.nid AND n.status = 1');

  $result-&gt;join('field_data_field_expired', 'fdfe', 'fdfe.entity_id = tn.nid');
  $result-&gt;condition('fdfe.field_expired_value', '1', '=');
  $result-&gt;condition('fdfe.entity_type', 'node', '=');

  $result-&gt;addExpression('COUNT(n.nid)', 'term_count');
  $temp = $result-&gt;execute();
  $temp = $temp-&gt;fetchObject();
  return $temp-&gt;term_count;
}


Another ways of patching it would be to add a module_invoke_all higher up the code to allow other modules to interact (hook into), or use "addTag" along your query and allow other modules to alter the query itself (the latest one would be recommended). Both this require you to write your own custom module.