I have a quite extensive database, 30000+ items, and using this:
$args = array( 'posts_per_page' => -1, 'post_type' => 'books', 's' => $s ); $post_counts = count(get_posts($args));
seems to take forever.
I solved this particular case with: $post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'books' AND post_status = 'publish' AND post_title LIKE '%".$s."%'");
But I have many queries that I'd like to count without having to write them by hand. Is there any way to count the posts with the $args using wordpress native functions without having to store the whole querie but only the count?