Skip to content

Instantly share code, notes, and snippets.

@mkwebworker
Created October 16, 2013 12:38
Show Gist options
  • Save mkwebworker/7007035 to your computer and use it in GitHub Desktop.
Save mkwebworker/7007035 to your computer and use it in GitHub Desktop.
count items of a category
/**
* count_categorie_items :: count all items of a category :: returns false or the number of items
* @param string $category_slug :: slug of the category
* @param bool return :: return or echo
**/
function count_categorie_items( $category_slug, $return = false){
if( ! empty ($category_slug) ):
///// get category id & count their items /////
$cat = get_category_by_slug($category_slug);
$args = array (
'post_type' => 'post',
'posts_per_page' => -1,
'category' => $cat->term_id
);
$press_releases_items = count( get_posts($args) );
///// return or echo /////
if($return == true )return $press_releases_items;
else echo $press_releases_items;
else:
return false;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment