• Hi all,

    How do I retrive the tags assigned to a post, using the post ID?

    If I use the UTW_ShowTagsForCurrentPost(), it echoes the tags, which is not the way to store into a variable.

    I’m making a plugin which provides links related to the post content. I’d also like to add the terms of the tags to analyze the content.

    If you know the way it would be greatly appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Maybe I misunderstand what you are after… but the UTW plugin has already a “show related posts” feature – based on tags. E.g.
    <?php UTW_ShowRelatedPostsForCurrentPost("posthtmllist") ?>

    Thread Starter goxu

    (@goxu)

    Thanks for the reply moshu,

    My words weren’t enough, excuse me. 🙂

    I mean not the links for related posts but for external links such as google’s search results or NEWS links. So I’m looking for a way to get tag names.

    global $wp_query;
    $post_id = $wp_query->post->ID;
    $tag_id = $wpdb->get_results(“SELECT tag_id FROM wp_post2tag WHERE post_id = “.$post_id);
    $tags = $wpdb->get_results(“SELECT tag FROM wp_tags WHERE tag_id = “.$tag_id);

    This doesn’t work. Well, I know I have to learn php and mysql coding more but it would be greatly appreciated if you know the solution.

    Thread Starter goxu

    (@goxu)

    Ok,

    When I do print_r($tag_id) with the code above, I get this.

    Array ( [0] => stdClass Object ( [tag_id] => 3 ) [1] => stdClass Object ( [tag_id] => 22 ) [2] => stdClass Object ( [tag_id] => 26 ) )

    It seems that it is not an usual array, doesn’t it? So how do I access to the actual numbers here?

    Hi goxu, did you try posting this on Christine’s forum? (She’s the plugin author….)

    http://neato.co.nz/forum/

    Thread Starter goxu

    (@goxu)

    Thanks vkaryl for the information. Next time I will ask a queston there.

    By the way, I figured out. But I think there must be a better way of doing this since the code below seems to be little awkward.

    <?php
    global $wp_query, $wpdb;
    $post_id = $wp_query->post->ID;
    $tag_ids = $wpdb->get_results(“SELECT tag_id FROM wp_post2tag WHERE post_id = “.$post_id);

    foreach($tag_ids as $index => $tag){
    $tag2[$index] = $wpdb->get_results(“SELECT tag FROM wp_tags WHERE tag_id = “.$tag->tag_id);
    }

    foreach($tag2 as $index2 => $tag3){
    $tag4[$index2] = $tag3[0]->tag;
    }

    print_r($tag4);
    ?>

    Well, if it works…. I don’t know anything about this sort of thing much, so it’s sorta one of those “greek to me” things.

    And I didn’t mean it wasn’t okay to ask here, just that sometimes the plugin author is a better option….

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘UTW: How to Retrieve Tags Assigned to a Post?’ is closed to new replies.