I have taxonomy with 4 Level State->District->Block->Villages. I want to get all villages of all Blocks of all Districts of a State.

I have done it by loops but my performance is very slow. please help me this take more time than expectation and very slow process.

enter image description here

  • What do you need to do with those 650.000 items? I suppose your are not showing all that items in the resulting page. If you explain why do you need them is easier to solve your problem. – sanzante Nov 5 '15 at 7:34
  • I have a Content Type for Village Data Where store particular State->District->Block->Village Data. I want to show records based on filters. I have a Role Village Auditor that check data by state and village auditor want to check how many Village Entries in particular State. – Kamal Oberoi Nov 5 '15 at 7:42
  • This doesn't explain whay you need to load all Villages at the same time. Why don't you use Views? – sanzante Nov 7 '15 at 13:34
  • i want to show add count for all village have any entry or not.. – Kamal Oberoi Nov 9 '15 at 5:10

You can fetch all child at any level by using this code :

function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
  $c = taxonomy_get_children($tid, $vid, $key);
  $result = array();
  foreach ($c as $t => $d){
    $result[$t] = $d;
    $below = taxonomy_get_children_all($t, $vid, $key);
    if (!empty($below)) {
      $result[$t]->children = array();
      foreach ($below as $nt => $nd){
        $result[$t]->children[$nt] = $nd;
  return $result;


You can do it by adding custom database query using function function taxonomy_get_children

  • I have also get by this function by it's very slow process because i have 6.5 lacs villages, 65 thousand blocks etc. thanks for your reply – Kamal Oberoi Nov 5 '15 at 6:10
  • when you have lots of data they system take some time to collect information – Adi Nov 5 '15 at 6:24
  • this is the main issue. performance for collecting data – Kamal Oberoi Nov 5 '15 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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