Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Forum: Plugins
    In reply to: [Simple News] Get News Tags
    Thread Starter chiffy

    (@chiffy)

    After investigating, I used the wrong function:
    get_terms(); using this spits out ALL tags that are defined.
    To list all Tags used by a SINGLE post one must use get_the_terms();

    So the final code:

    // Get Tags
    
    $args = array (
        'taxonomy' => 'newstags',
        'orderby' => 'name',
        'order' => 'ASC',
    );
    
    $tags = get_the_terms($post, 'newstags');
    if ( !empty($tags)  ) :
    foreach ( $tags as $tag ) {
        $tag_link = esc_url( get_tag_link( $tag->term_id ) );
        $html = '<span id="news-pill" class="badge badge-pill badge-secondary"><i class="fas fa-tag"></i> ';
        $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
        $html .= "{$tag->name}</a></span>";
            echo $html;
    }
    endif;
    Forum: Plugins
    In reply to: [Simple News] Get News Tags
    Thread Starter chiffy

    (@chiffy)

    Solved it. This works for me:

    <?php
    // Get Tags
    $args = array (
        'taxonomy' => 'newstags',
        'orderby' => 'name',
        'order' => 'ASC',
    );
    
    $tags = get_terms($args);
    foreach ( $tags as $tag ) {
        $tag_link = esc_url( get_tag_link( $tag->term_id ) );
        $html = '<span id="news-pill" class="badge badge-pill badge-secondary"><i class="fas fa-tag"></i> ';
        $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
        $html .= "{$tag->name}</a></span>";
        if ( !empty($tags)  ) :
            echo $html;
        endif;
    }

    Thanks anyway for your simple yet awesome plugin ??

Viewing 2 replies - 1 through 2 (of 2 total)