Reputation: 6696
I am looking for a way to present search results in my custom wordpress theme.
I was hoping being able to present the results like this:
Displaying 4 search results for "test"
Pages
Posts
I wrote a function is_type_page
that I can use inside the loop (2 loops), but this breaks the pagination functionality.
Any suggestions how to achieve this?
Upvotes: 4
Views: 2574
Reputation: 1
Running two loops is the way to go if you want them displayed with separate headers. Here is code to get them to show intermingles as they come up by date created...
<?php while (have_posts()) : the_post(); ?>
<?php if ( $post->post_type == 'page' ) { ?>
**DISPLAY PAGE**
<?php } else { ?>
**DISPLAY POST**
<?php else : endif; ?>
Upvotes: 2
Reputation: 447
I would run 2 separate loops on the page, after the first loop for pages run rewind_posts() and then run the loop again. Also the key to pagination is making sure the global $paged variable is being picked up on by both loops. $paged is how wordpress separates posts into pages. i.e. if you go to page 2 of something then the global $paged = 2.
Hope that helps
Multiple loops using rewind_posts here
Upvotes: 2