First, your callback to pre_get_posts
is wrong. That is not the way that set
works. If you had debugging enabled, you’d see Notices
. It should be:
function more_posts_per_search_page( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$query->set('posts_per_page',500);
$query->set('post_type',array( 'author', 'book'));
}
}
}
add_action( 'pre_get_posts','more_posts_per_search_page' );
Second, there is nothing built in that I am aware of that will return those numbers to you, but it isn’t hard to do using a WordPress Core function and a PHP one.
$types = wp_list_pluck($wp_query->posts,'post_type');
// var_dump($types); // debugging
$types_count = array_count_values($types);
var_dump($types_count); // your data
That code should be placed in your theme’s search.php
.