[resolved] How to get post tag? (6 posts)

  1. Luigino
    Posted 6 years ago #

    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!!

  2. MichaelH
    Posted 6 years ago #

    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);
  3. Luigino
    Posted 6 years ago #

    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....

  4. MichaelH
    Posted 6 years ago #

    $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> ';
  5. Luigino
    Posted 6 years ago #

    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?...


  6. MichaelH
    Posted 6 years ago #

    Luigino - please start another topic with that question.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.