I have been working on creating a custom loop and setting how many posts per page. I needed to make this loop separate to the blog posts per page – hence the custom loop.
Now the loop does work, however I noticed it is conflicting with the pagniation… pagination is showing but pages are not changing when you click ‘next’.
Here is my loop:
<?php
$args = array('posts_per_page'=>12, 'post_type' =>'office');
$category_posts = new WP_Query($args);
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
?>
<div class="office-item-wrapper">
<div class="office-item">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
</article>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article><!--/ Article -->
<?php endif; ?>
Thanks in advance to anyone who might be able to help me solve this issue 🙂
In WP, the pagination is sent by a
GET
variable underpage
, just add it to the query args:I recommend you to use
get_query_var('paged')
because if it’s empty it will be send you to the first page.Note: In some themes, the page number is sent in the
page
key, so try withpage
orpaged
.