Support » Plugins » How to get post tag?

  • Resolved Luigino


    Hello everyone…

    I have some posts which I assigned a tag to each of them to recognize when I do in a template:

    echo ‘<div class=”blahblah”><a href=”‘; echo get_page_link(xxx); echo ‘&focus=’; echo the_tags(); echo ‘” alt=”‘; echo the_title();….
    end loop…

    using the_tags() I thought it would return the tag I assigned to that post but I get something like “Tags: blah blah….”
    How I can get the single tag I assigned to the post??…

    Thanks in advance to all!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You don’t need to use echo with Template Tag, the_tags().

    If you want to return the post tags to a variable you can do this:

    $tags = wp_get_post_tags($post->ID);

    but with $tags I get an Array…since each post has only one tag just to identify that post, how I can get the tag from $tags’s array?.. with $tags[0] it doesn’t return the tag….

    $tags = wp_get_post_tags($post->ID);
      if ($tags) {
        foreach($tags as $tag) {
            echo '<p>' . $title . '<a href="' . get_term_link( $tag, 'post_tag' ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a> has ' . $tag->count . ' post(s). </p> ';

    Ah there we go! Thanks a lot MichaelH….
    Last question…outside the index.php, in this case in a theme for a plugin, where I adopt the query_posts(…), I get this error:

    Use of undefined constant date – assumed ‘date’ in /home/binago/public_html/wp-
    content/plugins/mailpress/mp-includes/class/MP_Mail.class.php(247) : eval()’d code at line 17

    so I supposed it’s due for this:

    $today = getdate();

    precisely in the ‘orderby’=>date maybe outside the usual loop posts doesn’t work…what do you think? is there maybe an alternative for this ‘orderby’=>date?…


    Luigino – please start another topic with that question.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to get post tag?’ is closed to new replies.