4

enter image description here 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->condition('tid', $tid);
  $result->join('node', 'n', 'n.nid = tn.nid AND n.status = 1');
  $result->addExpression('COUNT(n.nid)', 'term_count');
  $temp = $result->execute();
  $temp = $temp->fetchObject();
  return $temp->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.

3 Answers 3

1

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->condition('tid', $tid);
  $result->join('node', 'n', 'n.nid = tn.nid AND n.status = 1');

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

  $result->addExpression('COUNT(n.nid)', 'term_count');
  $temp = $result->execute();
  $temp = $temp->fetchObject();
  return $temp->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.

1
  • Can you also please give example in case I use revisions.
    – user5858
    Commented Oct 30, 2013 at 17:39
1

I think the best solution here is going to be to not use the taxonomy_menu module at all and write your own custom query to pull the terms with their counts out...

0

As a simple solution, why not set a Rule that when the content expires, it is either deleted, cached, or as a custom solution, the content is copied to another content type (say "Expired" for example) and then erased?

EDIT:

In order to keep the content "searchable" and viewable, create a Content Type called "Expired" (or whatever suits you) and put a View somewhere in your site that lists all of the content associated with this type. Then, do as suggested above with the Rule to copy the all the data out of the now hidden content, into a new piece of content of type "Expired". It is now searchable and viewable, you can even link the taxonomy terms if you wish via Views, and no need for custom code

3
  • I want the expired content to be visible if one reaches it thru Google anytime.
    – user5858
    Commented Nov 5, 2013 at 10:49
  • OK this should be relatively simple, create a Content Type called "Expired" (or whatever suits you) and put a View somewhere in your site that lists all of the content associated with this type. Then, do as suggested above with the Rule to copy the all the data out of the now hidden content, into a new piece of content of type "Expired". It is now searchable and viewable, you can even link the taxonomy terms if you wish via Views, and no need for custom code.
    – KyleM
    Commented Nov 5, 2013 at 11:20
  • I want to avoid this crude method.
    – user5858
    Commented Nov 5, 2013 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.