Title: Post Count for category and excludes sticky posts
Last modified: August 19, 2016

---

# Post Count for category and excludes sticky posts

 *  Resolved [John Leschinski](https://wordpress.org/support/users/picard102/)
 * (@picard102)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/post-count-2/)
 * I’m trying to display the number of posts in the current category archive. I 
   have this so far, but I want it to ignore sticky posts when it does the count,
   or if that’s not feasable minus one from the count every time.
 *     ```
       function wt_get_category_count($input = '') {
       	global $wpdb;
       	if($input == '')
       	{
       		$category = get_the_category();
       		return $category[0]->category_count;
       	}
       	elseif(is_numeric($input))
       	{
       		$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
       		return $wpdb->get_var($SQL);
       	}
       	else
       	{
       		$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
       		return $wpdb->get_var($SQL);
       	}
       }
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/post-count-2/#post-1084961)
 * Or this:
 *     ```
       <?php
       if ( is_category() ) {
         $cat = get_query_var('cat');
         $args = array(
       	'category__in' => array($cat),
       	'post_type' => 'post',
       	'showposts' => -1,
       	'post__not_in' => get_option('sticky_posts'),
       	'caller_get_posts' => 1
         );
         $cat_posts = get_posts($args);
         echo 'cat has this many non-sticky posts '. count($cat_posts);
       }
       ?>
       ```
   
 *  Thread Starter [John Leschinski](https://wordpress.org/support/users/picard102/)
 * (@picard102)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/post-count-2/#post-1084962)
 * Much simpler, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Post Count for category and excludes sticky posts’ is closed to new replies.

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [meh_code](https://wordpress.org/support/topic-tag/meh_code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [John Leschinski](https://wordpress.org/support/users/picard102/)
 * Last activity: [16 years, 11 months ago](https://wordpress.org/support/topic/post-count-2/#post-1084962)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
