get_posts won’t show the tags
-
Hello,
I’m building a custom theme and in the homepage (index.php), I’m showing 4 posts from different categories.
All is working OK with
get_posts
, the title and the content are shown as normal ; only the tags fail to appear.If I set up a conventional Loop, the tags show again.
Here it is one of my loops, the others are ‘clons’ but changing the category :
<?php $posts = get_posts('category=6&numberposts=1'); foreach($posts as $post): setup_postdata($post); ?> <?php the_title(); ?> <?php the_content(); ?> <?php the_tags(); ?> <?php endforeach; ?>
I’ve tried to do the same through WP_query, with no results :
<?php $my_query = new WP_Query('showposts=1&cat=4'); ?> <?php if (have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php the_title(); ?> <?php the_content(); ?> <?php the_tags(); ?> <?php endwhile; endif; ?>
I have several times worked with both, get_posts and WP_query (even if I ignore their differences, which it could be cool to know), and I don’t remember any issue.
Finally I tried to put a
rewind_posts
function, which I think it protects several Loops to ‘contaminate’ each other, but with no difference :<?php get_header(); rewind_posts(); ?>
Thanks for any input if anybody have some idea.
- The topic ‘get_posts won’t show the tags’ is closed to new replies.