After reading the documentation for multiple loops in one page here, I only had one WP_Query
for both the loops. I stored the ID’s of all the posts from the desired category and check for them in the second loop and continue
over them. Here’s the final code –
first loop
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'any',
'category' => 3,
'posts_per_page' => 4);
$query_var = new WP_Query($args);
if ($query_var->have_posts()):
while ($query_var->have_posts()):
$query_var->the_post();
$do_not_duplicate[] = $post->ID; ?>
<div class="patta p-4 col-lg-3 col-md-6">
<!-- FIX THIS -->
<img class="card-img-top"
src="https://wordpress.stackexchange.com/questions/323799/<?php the_post_thumbnail(); ?>"
alt="<?php the_post_thumbnail_caption() ?>"/>
<h4><b><?php the_title(); ?></b><br></h4>
<p>
<a href="#">Link</a>
</p>
</div>
<?php endwhile; ?>
Second Loop
if (have_posts()):
while (have_posts()):
the_post();
if (in_array($post->ID, $do_not_duplicate)) continue;
?>
<div class="patta p-4 col-lg-3 col-md-6">
<!-- FIX THIS -->
<img class="card-img-top"
src="https://wordpress.stackexchange.com/questions/323799/<?php the_post_thumbnail(); ?>"
alt="<?php the_post_thumbnail_caption() ?>"/>
<h4><b><?php the_title(); ?></b><br></h4>
<p>
<a href="#">Link</a>
</p>
</div>
<?php
endwhile;
endif;
endif;
?>