WordPress.org

Ready to get started?Download WordPress

Forums

Show all TAGS for each Post (3 posts)

  1. dekzgimutao
    Member
    Posted 2 years ago #

    I have three tables.

    posts
    | id | title |
    +---------+-----------+
    | 1 | hello |
    | 2 | goodbye |
    +---------+-----------+

    posts_tags
    | tag_id | post_id |
    +---------+-----------+
    | 1 | 1 |
    | 2 | 1 |
    | 2 | 2 |
    +---------+-----------+

    tags
    | id | name |
    +---------+-----------+
    | 1 | news |
    | 2 | photos |
    +---------+-----------+
    I want to be able to select the tags inside a post, and have this as a result

    post.id post.title tags
    ------------------------------------
    1 hello news,photos
    2 goodbye photos

    anyone? thanks

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    have you tried to use the_tags() ?

    http://codex.wordpress.org/Function_Reference/the_tags

  3. dekzgimutao
    Member
    Posted 2 years ago #

    Yes sir I've tried it It works on themes template but I'm creating a simple plugin which would show the follwing: Post Title Post Url and The TAGS inside each post a got it working with the title and url, i've tried different codes and so far I got a word Array and nots it value but when I print_r the variable it shows all the infomation of the TAGS

    <?php
        //echo "<br><br>";
        global $wpdb;
        $postID = $wpdb->get_col("
    	SELECT ID FROM $wpdb->posts
        WHERE (post_type = 'post')
    	AND (post_status = 'publish')
    	AND (post_password = '')
    ");
    
    echo '<ul id="post_links">';
    foreach($postID as $post_link) {
    
    	?>
     <tr> <td><a href="<?php echo get_permalink($post_link); ?>"><?php echo get_the_title($post_link);?> </a></td>
           <td><?php echo get_permalink($post_link); ?></td>
          <td><?php
                  echo get_the_tags($post_link);
                      $postid = $post->ID;
                     echo  get_the_tags($postid);
                     print_r(get_the_tags($post_link));
                      echo the_tags();
     ?>

    these is my code sir, Thanks I hope I can figure these out

Topic Closed

This topic has been closed to new replies.

About this Topic