mkwebworker
10/16/2013 - 12:38 PM

count items of a category

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;
 }