WordPress: Get the posts count for given category


/ Published in: PHP
Save to your folder(s)

Returns the number of published posts in the given category.


Copy this code and paste it in your HTML
  1. // @ WordPress
  2. // Returns the total number of posts in given category
  3. // --------------------------------------------------------
  4. function count_total_posts($cat) {
  5.  
  6. foreach((get_the_category()) as $category) {
  7.  
  8. if( $category->cat_ID == $cat ) return $category->category_count;
  9.  
  10. }
  11.  
  12. }
  13. //----------------------------------------------------------

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.