Including Future (Scheduled) Posts

This is a custom modification for the Count Posts in a Category plugin to allow the inclusion of future (scheduled) posts (or any post types other than “published”).

WordPress user TXALLDAY asks if this plugin (Count Posts in a Category) could be modified to include future (scheduled) posts. Yes! This is how:


(I decided against adding post_status as a shortcode attribute since few people would probably use it, and a much larger number would be confused by it. Plus, because this plugin uses get_term_by() to return an element with a built in (published) post count, it would make the code marginally efficient to have to run every request though get_posts() every time, or else I’d have to add separate functions, and it’s already pretty inefficient. But if a few people request this feature, I will find a way to add it… But I digress.)


The easiest way to do this is just to add a new shortcode called [cat_count_future]. For simplicity’s sake, it only accepts a category ID with the id="" attribute. I’m not sure if TXALLDAY wanted just scheduled posts, or scheduled posts and published posts, so I’ve also included the attribute future_only="no" so it can do it either way. By default (if omitted) it will count both, unless you set future_only="yes", then it will count scheduled only.


Open up the count_posts_in_cat.php file and add the following at the end (just before the closing ?>):

// category future posts count function
function cpina_future_count( $atts ) {
	// extract passed shortcode atts
	extract( shortcode_atts( array( 
		'id' => NULL,
		'future_only' => 'no' ), $atts ) ); 

	// count future + published or just future?
	$post_status = ( $future_only=='yes' ? 'future' : array( 'future', 'publish' ) );

	// build get_posts args
	$args = array(
		'numberposts' => 0, // unlimited # of results
		'category' => $id,
		'post_status' => $post_status );

	$posts = get_posts( $args ); // get matching posts
	return count( $posts ); // count matching posts
// register the shortcode 
add_shortcode( 'cat_count_future', 'cpina_future_count' );

Shortcode Use

Then use the shortcode [cat_count_future id="44" future_only="yes"] to count only scheduled posts in the category with the ID number 44. Or just [cat_count_future id="44"] to count published and scheduled posts in that category.


It will not count posts which are “pending review”, but if you want it to, just add the pending post status type to the array. In fact, you can mix and match post_status types to make your own function. The valid possible post_statuses are:

  • publish – a published post
  • pending – post pending review
  • draft – a saved draft
  • auto-draft – an auto-saved (blank) draft
  • future – a scheduled post
  • private – a private post
  • inherit – a revision (incremental save)
  • trash – a trashed post

If enough people want this functionality, I will include it in the next version of the default plugin.

One Thought on “Including Future (Scheduled) Posts

  1. Thank you for this wonderful plugin. I’ve tried and used it.


    p>I’ve been able to show total post, but overall (example : Showing 10 Products).


    p>Screenshot :


    p>How to display the total post per page. Suppose “Showing 5 of 10 Products”.


    p> Like this screenshot :



Leave a Reply

Your email address will not be published. Required fields are marked *