title: How to count the number of sub-terms under each parent term in WordPress
body: <p>I want to count the number of sub-terms under each parent term in WordPress.</p>
  <p>I have created a custom taxonomy in WordPress. I would like to display all the terms of this custom taxonomy on a custom page, such as:</p>
  <blockquote>
  <p><strong>1. I want to display all sub-terms under each parent term in the loop.</strong><br />
  <strong>2. I want to count the number of sub-terms under each parent term.</strong></p>
  </blockquote>
  <p>The number of posts under each term is being counted. But I'm in trouble with the sub-term.</p>
  <p>This is my code.</p>
  <pre><code>   &lt;?php 
        $args = array(
            'taxonomy' =&gt; 'pharma',
            'get' =&gt; 'all',
            'parent' =&gt; 0,
            'hide_empty' =&gt; 0
        );
        $terms = get_terms( $args );
        foreach ( $terms as $term ) : ?&gt;
        &lt;div class=&quot;single_pharma&quot;&gt;
          &lt;h2 class=&quot;pharma_name&quot;&gt;&lt;a href=&quot;&lt;?php echo esc_url( get_term_link( $term ) ); ?&gt;&quot;&gt;&lt;?php echo $term-&gt;name; ?&gt;&lt;/a&gt;&lt;/h2&gt;
  
          &lt;span class=&quot;count_category&quot;&gt;&lt;span&gt;Generics:&lt;/span&gt;&lt;?php // want to display here sub term count  ?&gt;&lt;/span&gt;
  
          &lt;span class=&quot;count_brand&quot;&gt;&lt;span&gt;Brands:&lt;/span&gt;&lt;?php echo $term-&gt;count; ?&gt;&lt;/span&gt;
        &lt;/div&gt;
  </code></pre>