• Resolved Galaxy_High

    (@galaxy_high)


    Hello,

    First and foremost, great plugin. I use it all the time.

    I’m running into difficulties trying to add the label for group tags and I’m not sure what I’m doing wrong.

    I’ve used this code…

    $tags = get_the_tags();
    $html = '<div class="tags">' . "\r\n" . '<ul>' . "\r\n" . '<li>Tags: </li>' . "\r\n" . '';
    foreach ( $tags as $tag ){
       $tag_link = get_tag_link( $tag->term_id );
    		
       $term = get_queried_object();
       $tag_group_labels = get_option( 'tag_group_labels', array() );
       $tag_group_ids = get_option( 'tag_group_ids', array() );
       $i = array_search($term->term_group, $tag_group_ids);
    		
       $html .= "<li><a href=\"{$tag_link}\" title=\"{$tag->description}\n\n";
       $html .= "Tagged in " . $tag->count . " posts\n\n";
       $html .= "Catergory: " . $tag_group_labels[$i] . " ";
       $html .= "\"class=\"group" . $tag->term_group . " " . $tag->slug . " tag\">";
       $html .= "{$tag->name}";
       $html .= "</a></li> \n";
       }
    $html .= '</ul>' . "\r\n" . '</div><!--end tags-->';
    echo $html;

    ..but all its spitting out is “not assigned”

    I have my tags and tag groups set up as I’m able to use the other functions $tag->description, $tag->slug, $tag_link, etc. when styling the output.

    Could you point me in the right direction?

    Regards,
    Sam

    • This topic was modified 7 years, 9 months ago by Galaxy_High. Reason: Tidying up formatting
Viewing 3 replies - 1 through 3 (of 3 total)
  • I think, if you just want to list all tags, you don’t actually need
    $term = get_queried_object();

    In the array_search you can then use $tag-> instead of $term->
    $i = array_search($tag->term_group, $tag_group_ids);

    Currently, you get most of the data from $tag and only the group affiliation from $term. While $tag changes in the foreach loop, $term remains the same and doesn’t match.

    Thread Starter Galaxy_High

    (@galaxy_high)

    Brilliant!

    Thanks for the explanation regarding $tag / $term.

    Been out of the loop, so to speak, regarding wordpress. It’s slowly coming back to me.

    Thanks again,
    Sam

    ??

    You’re most welcome!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘$tag_group_labels’ is closed to new replies.