Support » Plugin: Tag Groups is the Advanced Way to Display Your Taxonomy Terms » When post has no tags, tag_groups_cloud shows all tag groups

  • Resolved Lea

    (@leac)


    I want to get each post’s tag cloud. However, what happens if a post doesn’t have any tags assigned to it, tag_groups_cloud returns all the groups and all their tags. That’s not what I want at all… This is my code, run within The Loop:

    $tag_group_args' = array( 'orderby' => 'count', 'order' => 'DESC', 'tags_post_id' => 0 );
    $groups = tag_groups_cloud( $tag_group_args, true );
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thanks for reporting, I will take a look as soon as I have time.

    You can try as quick fix to add on line 2515 after

    
    if ( $post_id_terms ) {
    ...
    }
    

    to add

     else {
                $posttags = array();
            }
    
    Thread Starter Lea

    (@leac)

    Thank you! That helps.
    What I need to do now is add a check for the ‘tags’ index before using it in this example. It needs to be done right after tag_groups_cloud is called, because if there are no tags, then no use creating the table.
    Update: It doesn’t work. When no tags_post_id is passed, $post_id_terms is empty, and enters the else that we added, which results in no tags in the object that tag_groups_cloud returns.

    • This reply was modified 7 years, 6 months ago by Lea. Reason: added update about code
    • This reply was modified 7 years, 6 months ago by Lea. Reason: added update about code
    Thread Starter Lea

    (@leac)

    Update: found a fix. The condition on line 2387 if ( $tags_post_id ) returns true even when $tags_post_id is -1. So I changed the condition to if ( $tags_post_id > -1 ).

    ok, thanks, I will check that too

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘When post has no tags, tag_groups_cloud shows all tag groups’ is closed to new replies.