Better exposed fiters with Views: how to show quantity of nodes tagged with certain term? I use better exposed filters with views. I chose to show field "term reference" as hierarchical checkboxes on my exposed filter. It works great.

But now I need to add quantity of nodes having certain term near each checkbox inside filter.
What is the best way to do it?
Thank you!
I ended up with editing \sites\all\modules\better_exposed_filters\better_exposed_filters.theme

Inside it I made a query to field_data_, got all terms with nodes count:

function theme_select_as_checkboxes:

$res = db_query('SELECT field_dance_styleee_tid, COUNT(*) as count FROM field_data_field_dance_styleee
 GROUP BY field_dance_styleee_tid');
    $allNodes = array();
    while($record = $res->fetchAssoc()){
        $allNodes[$record['field_dance_styleee_tid']] = $record;
    }

Then passed $allNodes to

  $output .= bef_checkbox($element, $key, $value, array_search($key, $selected_options) !== FALSE, $allNodes);


function bef_checkbox($element, $value, $label, $selected, $allNodes=array()) {

$value = check_plain($value);
  $label = check_plain($label);
  $id = drupal_html_id($element['#id'] . '-' . $value);
  // Custom ID for each checkbox based on the 's original ID
  $properties = array(
    '#required' => FALSE,
    '#id' => $id,
    '#type' => 'bef-checkbox',
    '#name' => $id,
  );

// Prevent the select-all-none class from cascading to all checkboxes
  if (!empty($element['#attributes']['class'])
      &amp;&amp; FALSE !== ($key = array_search('bef-select-all-none', $element['#attributes']['class']))) {
    unset($element['#attributes']['class'][$key]);
  }

// Unset the name attribute as we are setting it manually.
  unset($element['#attributes']['name']);

$checkbox = '';

$properties['#children'] = "$checkbox $label". ((
      $element['#name'] == 'field_dance_styleee_tid' &amp;&amp; isset($allNodes[$value])
  )? "(".$allNodes[$value]['count'].")" : '')."";

$output = theme('form_element', array('element' => $properties));
  return $output;
}