Support » Themes and Templates » Can’t get tags to show up in WP_Query loop…

  • Hi,

    I am trying to use tags in a custom query:

    <?php $homeArticle = new WP_Query();
    		while ($homeArticle->have_posts()) : $homeArticle->the_post(); ?>
    		<div class="postWrapper">
    			<span class="entryTitle">
    				<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    				<h4>by <?php the_author(); ?>, posted <?php the_time('F, j Y'); ?> at <?php the_time(); ?></h4>
    			<? the_content();?>
    			<div class="post_meta">
    				<p>Posted in: <?php the_category(', '); ?></p>
    				<?php the_tags('<ul><li>','</li><li>','</li></ul>'); ?>
    	<?php endwhile; ?>

    But for some reason they never show up… Putting them in a standard Loop seems to be fine though…

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have you tried throwing the post id to the get_the_tags function? So, something like this:

    <div class="tag_list">tags:
        $tags = get_the_tags($post->ID);
        foreach($tags as $tag) {$total_tag_count++;}
            $tcount = 0;
            foreach($tags as $tag)
                $tag_name = $tag->name;
                $tag_slug = $tag->slug;
                echo '<a href="/tag/'.$tag_slug.'" title="'.$tag_name.'">'.$tag_name.'</a>';
                if ($tcount < $total_tag_count)
                   echo ", ";

    You could probably clean up the first foreach so you only have to use one, but this should give you a general idea.


    @silentgap – I pasted this code right into my custom wp_query, and it worked like a charm – thanks!

    I’ll clean it up for my own needs, of course.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can’t get tags to show up in WP_Query loop…’ is closed to new replies.