1

I needed to list all existing tags so I have some code that does it. Now I would like to put the count (the number of posts the tag is associated with) in front the tag like in the example given below.

    first_tag  - 18
    second_tag - 24
    third_tag  - 48

I found a solution given here that displays count for one specific tag, but I need the counts for each and every tag. So, could this be modified to my need. Or do you have any other ideas. Will appreciate your help.

$taxonomy = "post_tag"; 
$term_slug = 'some-tag';
$term = get_term_by('slug', $term_slug, $taxonomy);
echo $term->count;
2
  • Please post your working (or not working) code so that people who may want to help don't have to visit two additional questions and combine the result to get enough information to begin to think about the problem. – s_ha_dum Mar 22 '14 at 17:12
  • I have improved the question. Now there is just this non-working code. – gurung Mar 22 '14 at 17:18
2

It is still not very clear what you are trying to do, but maybe get_terms() is what you want.

$terms = get_terms('post_tag',array('hide_empty'=>false));
foreach($terms as $t) {
  echo $t->name.' :: '.$t->count.'</br>';
}
1
  • Exactly what I needed. This gives tags as strings but I can get the links using get_tag_link. Thanks. – gurung Mar 22 '14 at 17:36

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.