WordPress.org

Forums

retrieving tags (4 posts)

  1. asquare
    Member
    Posted 7 years ago #

    hi

    I'm using a custom select to retrieve my posts for my posts page instead of the loop. I need to get each posts tags as I display the post.

    get_the_tags($post->ID);
    this (above) seems to work and then I have to construct my string from the arrays, making sure I add links and commas between tags etc.

    is there an easier way to do this?

    a+
    gar

  2. Dunkkan
    Member
    Posted 6 years ago #

    Hi asquare, did you get a solution to this ? I'm involved in the same issue.

  3. whooami
    Member
    Posted 6 years ago #

    <?php the_tags('<span class="taglist"><strong>Tags:</strong></span> &nbsp;', ', ', ''); ?>

  4. Dunkkan
    Member
    Posted 6 years ago #

    Hi whooami, I tried this inside a custom query with get_posts, but it didn't work.

    Here's what I found to solve it. If someone knows a better way, please share it !

    <?php
    		 $posts = get_posts('category=4&numberposts=1');
    		 foreach($posts as $post):
    			setup_postdata($post);
    		 ?>
    		<?php the_title(); ?>
    		<?php the_content(); ?>
    
    		<!-- HERE IT COMES THE TRICKY PART -->
    
    		<?php $posttags = get_the_tags($post->ID);
    		if ($posttags) {
    		foreach($posttags as $tag) {
    		echo $tag->name . ' ';
    		}
    		}
    		?>
    		<?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic