1

I am trying to build a custom tag cloud widget. If I view post #1 which has tags of foo,bar,code it says the counts for all those tags are 0, even if post #2 uses the exact same tags. I have a frontend form that modifies the post's tags with the following:

wp_set_post_tags($this->id, $_POST['tags']);

Then, when I view the post, i get the tags with

$tags = get_the_tags(get_the_ID());
if(count($tags) > 0){
    foreach($tags as $tag){
       echo $tag->name."(".$tag->count.")";
    }
}

In the above code, $tag->name returns the correct tags for each post, but $tag->count is always 0. Does wp_set_post_tags maybe not update the counts in the wp_term_taxonomy data table? Should I use something other than wp_set_post_tags or something other than get_the_tags?

1

try this:

$tags = get_the_tags(get_the_ID());
if(count($tags) > 1){
    foreach($tags as $tag){
       echo $tag->name."(".$tag->count.")";
    }
}

The get_the_tags_ function returns an array buts indexes do not begin at 0 as they are term ID's

  • Sorry, i meant $tag->count always returns 0, not count($tags) – ShoeLace1291 Dec 13 '17 at 0:32

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.