You would have to perform the query for each respective tab. If you are using WP_Query then you can perform the query and then use $found_posts
to return the total number of posts matching that query. For instance,
$query_tab_1 = new WP_Query($args); //Where $args is some arguments for your query
$tab_1_count = $query_tab_1->found_posts;
The $query_tab_1
object will have all the returned posts, so inside the appropriate ‘section’ you could just loop through that:
if($query_tab_1->have_posts()):
while ($query_tab_1->have_posts() ) : $query_tab_1->the_post();
//Display tab 1's loop here
endwhile;
endif;
See the Codex on the WP_Query object. If you aren’t using the WordPress API, then you could use a MYSQL COUNT query to return the number of hits for each query..
Dislaimer: I haven’t tested this – but it should work.
EDIT
There appears to be some people experiencing issues with this method – it seems to a php bug (but some have managed to fix it, see link). As alternative (and assuming you don’t want pagination – you could try get_posts
which returns an array of posts, and then use php’s count
. It’s not as elegant but hopefully the related link will help solve the issue…