search: get minimum number of post for each post type

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 <?php $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() … Read more

Build A Custom SQL Query for WordPress Search

A possible solution is to use the pre_get_posts action: add_action(‘pre_get_posts’, ‘custom_search_query’); function custom_search_query($query) { // run only if is a search query and if the search string is not empty if($query->is_search() && $query->is_main_query() && get_query_var(‘s’, false)) { // here you can use your custom query having ‘get_query_var(‘s’, false)’ as $Search string //”SELECT SQL_CALC_FOUND_ROWS *………. // … Read more