Can't get tags to show up in WP_Query loop... (3 posts)

  1. nipponese
    Posted 7 years ago #


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

  2. silentgap
    Posted 6 years ago #

    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.

    ref. http://wordpress.org/support/topic/252955

  3. jcdesign
    Posted 6 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic