I want to display all posts with the Projekty wnętrz category. Im using this query to achieve this, but it shows only few of posts (I added 8 and it shows only 6. I want to show always every post).
I have this problem with every category and it always shows only part of posts.
Thanks in advance 🙂
<div id="menu1" class="tab-pane fade">
<div class="container">
<div class="row">
<?php $args = array( 'post_type' => 'Realizacje'); ?>
<?php $loop = new WP_Query($args); ?>
<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
$num = $loop->post_count;
$cat_id = get_cat_ID( 'Projekty wnętrz' );
if (has_category( $cat_id )) {
?>
<div class="col-md-4">
<div class="realisation">
<!-- <div class="gallery">
<?php
$images = get_field('galeria');
$size = 'medium';
if( $images ): ?>
<div id="lightgallery<?php echo $count; ?>">
<?php foreach( $images as $image ): ?>
<div class="gal">
<img src="<?php echo $image; ?>"/>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div> -->
<div class="galeria">
<div class="lightg" id="lightgallery<?php echo $count; ?>">
<a href="<?php echo get_the_post_thumbnail_url(); ?>">
<div class="relative-box"><img class="first_image"src="<?php echo get_the_post_thumbnail_url(); ?>"/>
<div class="demo-gallery-poster">
<i class="fa fa-search" aria-hidden="true"></i>
</div></div>
<div class="gallery-title"><h5 class="gallery-t"><?php the_title(); ?></h5></div>
</a>
<?php
$count=$count+1;
$images = get_field('galeria');
$size = 'large';
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image; ?>"><img src="<?php echo $image; ?>"/></a>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php } ?>
<?php endwhile; ?>
<?php else: ?>
<h5>Brak realizacji</h5>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
</div>
2
Answers
You’re not using any pagination parameters so it’s possible you’re getting only 10-12 posts from query based on how many posts per page value is set on backend settings.
Then on top of that, you are using
has_category( $cat_id )
to exclude the post content, You should not do this and should pass the category ID/slug in category parameters, You should not use the name, You must work with category ID or slug.Since you need all the posts from the category then you need to set
posts_per_page
to-1
, and-1
will display all the posts with all the filters used in Query.the code will look like this after applying the above changes:
Please check below full code. I’ve tested and it’s working fine.