Separate posts and pages from WordPress search results

I am looking for a way to present search results in my custom Wordpress theme.

I was hoping to present the results as follows:


Showing 4 search results for "test"

Pages

  • testpage 1
  • testpage 2

Messages

  • testpost 1
  • testpost 2

I wrote a function is_type_pagethat I can use inside a loop (2 loops), but this violates the pagination functionality.

Any suggestions to achieve this?

+3
source share
2 answers

2 , , rewind_posts(), . , $paged . $paged - Wordpress . .. 2 -, $paged = 2.

,

rewind_posts

+1

- , , . , , , ...

<?php while (have_posts()) : the_post(); ?>
<?php if ( $post->post_type == 'page' ) { ?>
         **DISPLAY PAGE**
<?php } else  { ?>
         **DISPLAY POST**
<?php else : endif; ?>
+1

Source: https://habr.com/ru/post/1769134/


All Articles