Created
October 16, 2013 12:38
-
-
Save mkwebworker/7007035 to your computer and use it in GitHub Desktop.
count items of a category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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