SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast fatihturan's Avatar
    Join Date
    Aug 2008
    Location
    Turkey
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Getting Post's Tags on Wordpress Without Use Loop

    Hello.

    How i can get post's tags on Wordpress without use loop? I think i can get tags from through DB but i don't know how i can do this.

    Thanks.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There's a (not well documented) function you can use to get the tags for a post by ID: wp_get_post_tags($id). This returns an array of tag objects. To get the ones you're probably looking for in text:

    PHP Code:
        $existing_tags wp_get_post_tags($post->ID);

        
    $tags = array();
        if (
    count($existing_tags) > 0) {
            foreach (
    $existing_tags as $tag) {
                if (
    $tag->taxonomy == 'post_tag')
                    
    $tags[] = $tag->name;
            }
        }
        
    //now use $tags array of tag names 
    There are also functions for adding, updating, deleting tags on a post. You don't need to hit the database directly.
    Last edited by Dan Grossman; Oct 14, 2008 at 02:42. Reason: Added more info

  3. #3
    SitePoint Enthusiast fatihturan's Avatar
    Join Date
    Aug 2008
    Location
    Turkey
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah thanks. It's worked perfectly.

  4. #4
    SitePoint Enthusiast websavy's Avatar
    Join Date
    May 2008
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for your valuable input... It is really works fine.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •