I am using the code below to show search results for different post types separately/segmented form.
if (have_posts()) {
// In the below line of code you can set the loop order in array (1, 2, 3, 4)
// You can also turn a post type off by removing it from the below line.
$types = array('post', 'page', 'sfwd-courses', 'product');
foreach ($types as $type) {
// Here you can customize both the titles, section heading title & side title
if ($type == 'post') {
$head_title = "Results in Posts";
$side_title = "post";
}
if ($type == 'page') {
$head_title = "Results in Pages";
$side_title = "page";
}
if ($type == 'sfwd-courses') {
$head_title = "Results in Courses";
$side_title = "course";
}
if ($type == 'product') {
$head_title = "Results in Products";
$side_title = "product";
}
// This div below shows up the head title for each section
echo '<div class="search-section"><h4>' . $head_title . '</h4></div>';
while (have_posts()) {
the_post();
if ($type == get_post_type()) {
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(''); ?> role="article">
<header class="article-header">
<div class="article-header-content">
<h3 class="title head-2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<!-- This div below shows up the side title for each section -->
<div class="posttypetext"><i> <?php echo $side_title; ?> </i></div>
</div>
<!-- <?php get_template_part('parts/content', 'byline'); ?> -->
</header> <!-- end article header -->
</article> <!-- end article -->
<?php }
}
rewind_posts();
}
} else {
get_template_part('template-parts/content', 'missing');
}
This shows me a list of search results showing all the posts first and then the results from pages, then courses and finally products.
The pagination limit right now is 20 per page.
I want that on each page I should get 5 search results from post, 5 from page, 5 courses and 5 products.
this is needed because if there are 30-40 posts results, it will cover up the first 2 pages of search results and users will not see any courses or products that will be lying on the 3, 4 page.
I hope it makes sense, is there a way to accomplish that?
Thanks JS