I've a small issue with the default search, I want to search cross different post_types and returning for example 5 items. In this moment if I search for the word: foo and this word is in 10 wc products, 3 posts and 8 pages the search will return the the 5 product but it will not return any posts or pages, what I would like to have is that the search return:

5 products
3 posts
5 pages

is it possible somehow?

1 Answer 1


My first guess will be to run multiple custom queries on your search.php template in order to change post_type and posts_per_page

It could look like that

$s = get_search_query();
$args_array = [
  {'s' =>$s,'post_type'=>'products','posts_per_page'=>5},
  {'s' =>$s,'post_type'=>'posts','posts_per_page'=>3},
  {'s' =>$s,'post_type'=>'pages','posts_per_page'=>5},
foreach( $args_array as $args ) {
  $the_query = new WP_Query( $args );
  while ( $the_query->have_posts() ) : $the_query->the_post();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.