WordPress get_post_count?
        Posted  
        
            by Scott B
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Scott B
        
        
        
        Published on 2010-03-23T23:12:54Z
        Indexed on 
            2010/03/23
            23:13 UTC
        
        
        Read the original article
        Hit count: 405
        
I'd like to create a function that retrieves the post count for a given query. I don't want to use get_posts obviously as its way to expensive for this purpose. However, that's exactly what I'm having to use in absense of a get_post_count function.
My code is...
global $post;
$cat=get_cat_ID('mymenu');
$catHidden=get_cat_ID('hidden');
$myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'showposts' => $NumberOfPostsToShow));
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat,-$catHidden",'showposts' => -1));
$myrecentpostscount = count($myrecentposts2);
© Stack Overflow or respective owner