0

i have a problem with the 'posts_per_page'- no matter that i set it to, e.g 10 or 0, it always only show one post!

<?php $loop = new WP_Query( array( 'post_type' => 'producenter', 'posts_per_page' => 0, 'orderby' => 'rand', 'post__not_in' => array($post->ID) ) ); ?>
<p class="loop__title">Andre leverandører:</p>
<ul class="grid__content small">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h4><?php the_title(); ?></h4>
<?php if( get_field( "deloverskrift" ) ): ?>
<p><?php the_field( "deloverskrift" ); ?></p>
<?php endif; ?>
</a>
</li>
<?php endwhile; ?>
</ul>

1 Answer 1

0

0 isn't a valid value for posts_per_page. WordPress will see it as empty and default to the posts_per_page option. If you want all the posts use nopaging or posts_per_page => -1.

$query = new \WP_Query([
  'post_type' => 'producenter',
  'nopaging' => true,
  'orderby' => 'rand',
  'post__not_in' => [$post->ID],
]);

As far as why it's only showing 1 post, is that what you have set in the default posts per page option? Not sure why it would only show one post if you set posts_per_page to 10.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.