I'm working on a WordPress site, on it I've got a page with posts filtered by select option. Select option having different resource types. I've got 100 more posts for each resource type, but I want to display 10 posts per page, and the remaining should get pagination. My code:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' =>10,
'offset' => 0,
'paged' => $paged,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
if(isset($args3) && !empty($cat_termId)){
$query = new WP_Query( array( 'category__and' => array($cat_termId) ) );
$posts = $query->posts;
}else{
$args1 = !empty($args2)?$args2:$args1;
$args = array_merge($args,$args1);
$posts = get_posts( $args );
}
endif;
if(!empty($posts) && !empty($cat_termId)){
echo '<div class="row mt-5 insight-page-data search-insights" id="sub-insights">';
foreach ($posts as $post){
//Post Details
$post_content = $post->post_content ;
$post_excerpt = wp_trim_words($post->post_excerpt, 10) ;
$post_name = $post->post_title ;
$name = $post->post_name ;
$link = get_the_permalink($post->ID);
$image =wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID),'full');
?>
<div class="col-sm-6 col-md-6 col-lg-4 my-3 wow fadeIn animated" data-wow-duration="1s" data-wow-delay=".3s">
<div class="card border-0 rounded-0 <?=$card?>" >
<div class="card-header border-0 py-2">
<img src="<?=$card_link?>" alt="" class="mr-2"><?= ucfirst($main_slug_name)?>
</div>
<div class="card-img-top card-img rounded-0 align-middle">
<a href="<?=$link?>"><img class="mx-auto d-block align-middle" src="<?php echo !empty($image[0])?$image[0]:$defaultImg?>" alt="MSR Cosmos <?= $main_slug_name?>"/></a>
</div>
<div class="card-body" id="alink1">
<h4 class="card-title"><a href="<?=$link?>" rel="noreferrer"><?=$name?></a></h4>
<p class="card-text"><?=$post_excerpt?></p>
</div>
</div>
</div>
<?php }
echo '</div>';
} else{
echo "<p class='no-results'>No Insights Available</p>";
}
}
?>
Please help me to get the desired result. Am I really on the right path?