The following code is working great, except for an intermittent (seemingly random) glitch: sometimes instead of getting two (2) posts to show, it only gets one (1). ???
I have verified that the categories have more than 2 posts of the right type in the instances where this is happening. It’s not because there are no more posts to be pulled.
Can anyone think of any possible avenues to check as to why?
<?php $args = array( 'type' => 'book', 'child_of' => 13, 'orderby' => 'id', 'order' => 'ASC', 'hide_empty' => 1, 'hierarchical' => 0); $cats = get_categories( $args ); foreach ($cats as $cat): $catID = $cat->term_id; $catName = $cat->name; $catSlug = $cat->slug; $args = array( 'post_type' => array('books'), 'cat' => $catID, 'posts_per_page'=> 2, 'offset'=>0, 'orderby'=>'rand'); $wp_query= null; $wp_query = new WP_Query(); $wp_query->query($args); ?> <?php if ( $wp_query->have_posts() ) : ?>
- The topic ‘WP_Query 'posts_per_page' sometimes getting fewer posts than should’ is closed to new replies.