i have a wordpress site that has around 20000 post
it gets slow at generating pagination. i have traced the problem.

$my_query = new WP_Query($query_string ."&posts_per_page=-1");
$total_posts = $my_query->post_count;

is there any other faster way to get total post on a selected category.

3 Answers
3

I have one solution for you.
This code will show and unordered list with the name of the category and the count of posts containded in it.

<ul class="myClass">
 <?php $categories = get_categories('number=100');
       foreach ($categories as $cat) {
       echo "<li>". $cat->cat_name . " Total posts: ". $cat->category_count ."</li>";
       } ?>
</ul>

Retrieves the 100 first categories

$categories = get_categories('number=100');

and for each of them shows cat_name and category_count

Well the result I presume you really need can now be handled in a var by $cat->category_count, i.e:

$total_num_posts_in_your_category = $cat->category_count

I hope that could help you.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *