I have an issue with adding a Grid Layout to my Projects here is the code:
<?php while ( have_posts() ) : the_post(); ?>
<?php
$args = array(
'post_type' => 'projects',
'posts_per_page' => 2,
);
$q = new WP_Query( $args );
?>
<div class="row">
<?php while ( $q->have_posts() ) : $q->the_post(); ?>
<div class="col-6">
<h3>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php endwhile; ?>
And its Looks like this: The Image. It's simply repeats the 2-column Grid as many time as I have posts.
Can anyone help me to fix this, to get a normal Grid layout for my projects?
Thanks!
Remove <?php while ( have_posts() ) : the_post(); ?>
from top and <?php endwhile; ?>
from bottom. Because you have a custom WP query inside that loop. So no need of default Wordpress post query loop there.