WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the below code to display the list (radio buttons) of terms that are currently used by existing custom post type posts:

$args = array( 
  'taxonomy' => 'typ',
  'post_type' => 'instytucje',
$terms = get_terms('typ', $args);
$count = count($terms); $i=0;
if ($count > 0) {
    $cape_list = '';
    foreach ($terms as $term) { 
        $term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . '';
        if ($count != $i) $term_list .= '<br>'; else $term_list .= '<br>';
    echo '<form name="filterby" action="" method="GET">';
    echo $term_list;
    echo '<button OnClick="document.filterby.submit();">Szukaj</button>';

The list is used as a form to filter posts by terms.

My question is - how can I add a counter showing the number of posts next to each term on the list?

[radio button] [term name] [number of posts with the term]

This is the site I am working on:

share|improve this question

Replace the 11th line with the code below (untested):

$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . ' Number of Posts:'. $term->count;

It appears that get_terms has a post count return value.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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