• Hi,

    I am trying to use tags in a custom query:

    <?php $homeArticle = new WP_Query();
    		$homeArticle->query('showposts=10');
    		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>
    			</span>
    			<? the_content();?>
    			<div class="post_meta">
    				<p>Posted in: <?php the_category(', '); ?></p>
    				<?php the_tags('<ul><li>','</li><li>','</li></ul>'); ?>
    			</div>
    		</div>
    	<?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:
    <?php
        $tags = get_the_tags($post->ID);
        $total_tag_count=0;
        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>';
                $tcount++;
                if ($tcount < $total_tag_count)
                {
                   echo ", ";
                }
            }
    ?>
    </div>

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

    ref. https://www.ads-software.com/support/topic/252955

    @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.