Original question: Seperating Custom Post Search Results
I’ve tried to implement this code to my website, but i have some problem with it.
What i’ve changed is i’ve added another switch for third post type, as follows:
<?php if (have_posts()) : ?>
<?php
$last_type = "";
$typecount = 0;
while (have_posts()) :
the_post();
if ($last_type != $post->post_type) {
$typecount = $typecount + 1;
if ($typecount > 1) {
echo '</div><!-- close container -->'; //close type container
}
// save the post type.
$last_type = $post->post_type;
//open type container
switch ($post->post_type) {
case 'post':
echo "<div class=\"postsearch container\"><h2>Blog Results</h2>";
break;
case 'partner':
echo "<div class=\"partnersearch container\"><h2>Partner Search Results</h2>";
break;
case 'fiches_pratiques':
echo "<div class=\"lessonsearch container\"><h2>lesson Search Results</h2>";
break;
}
}
?>
<?php if ('post' == get_post_type()) : ?>
<li class="post"><?php the_title(); ?></li>
<?php endif; ?>
<?php if ('partner' == get_post_type()) : ?>
<li class="partner"><?php the_title(); ?></li>
<?php endif; ?>
<?php if ('lesson' == get_post_type()) : ?>
<li class="lesson"><?php the_title(); ?></li>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<div class="open-a-div">
<p>No results found.</p>
<?php endif; ?>
This code results in following:
Lessons Search Results
Lesson 1 Lesson 4 Lesson 3
Blog Results
Test sub
Partner Search Results
Fourth partner
Blog Results
Lorem ipsum Wave 2.0 Web & Tech Cloud Open Container Project
As you can notice, the blog results section is doubled.
Any suggestions on what might be the problem?
Installed search plugins:
Relevanssi
NOTE: without Relevanssi (but with Search Everything plugin) it shows it in a proper way, but Search Everything plugin doesn’t allow multiple terms search, which is a must have in my case.
Latest WordPress version.
Thank you in advance.