I am using hook_views_pre_view to add some filters/modifications to the 'taxonomy_term' view, based on the terms vocabulary.

In another module (taxonomy_menu) I have the code below. I just want to get the result count of the 'taxonomy_term' view with any hook_views_pre_view's already applied. However it is ignoring my hook_views_pre_view.

 function _taxonomy_menu_term_count($tid){ 
  $view = views_get_view('taxonomy_term');
   $args = array($tid);
   $view->set_arguments($args);
   $view->execute();
   return count($view->result);
 }

I have tried adding "$view->pre_execute();" before "$view->execute();", but that caused a white screen.

Any thoughts?

Thanks,
-Todd

Comments

TPerkins’s picture

You need to use something like execute_display, since all of you mods made within hook_views_pre_view are part of a display.

This works:

   $view = views_get_view('taxonomy_term');
   $args = array($tid);
   $view->set_arguments($args);
   $view->execute_display('page', $args);
   return $view->total_rows;