I'm trying to display a list of pages on an archive page. The query I've written is meant to only fetch pages but for some reason it is also displaying one post (from the archive page this is on) amongst the pages.
Can anyone suggest what the issue is?
Thanks in advance.
<?php $page_args = array(
'post_type' => 'page'
); ?>
<?php $page_query = new WP_Query($page_args); ?>
<div class="links_slider">
<a class="slide" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('links'); ?>
<span><?php the_title(); ?></span>
</a>
<?php while($page_query->have_posts()):$page_query->the_post(); ?>
<a class="slide" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('links'); ?>
<span><?php the_title(); ?></span>
</a>
<?php endwhile; ?>
</div>
I'm trying to display a list of pages on an archive page. The query I've written is meant to only fetch pages but for some reason it is also displaying one post (from the archive page this is on) amongst the pages.
Can anyone suggest what the issue is?
Thanks in advance.
<?php $page_args = array(
'post_type' => 'page'
); ?>
<?php $page_query = new WP_Query($page_args); ?>
<div class="links_slider">
<a class="slide" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('links'); ?>
<span><?php the_title(); ?></span>
</a>
<?php while($page_query->have_posts()):$page_query->the_post(); ?>
<a class="slide" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('links'); ?>
<span><?php the_title(); ?></span>
</a>
<?php endwhile; ?>
</div>
The issue turned out to be in another part of my code and nothing to do the the above query, which works just fine.
Apparently this part of code before while loop is introducing undesired result.
<a class="slide" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('links'); ?>
<span><?php the_title(); ?></span>
</a>
So the revised code should be something:
<?php $page_args = array(
'post_type' => 'page'
); ?>
<?php $page_query = new WP_Query($page_args); ?>
<div class="links_slider">
<?php while( $page_query->have_posts() ): $page_query->the_post(); ?>
<a class="slide" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('links'); ?>
<span><?php the_title(); ?></span>
</a>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>