Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created March 18, 2013 09:49
Show Gist options
  • Save thefuxia/5186068 to your computer and use it in GitHub Desktop.
Save thefuxia/5186068 to your computer and use it in GitHub Desktop.
Count posts in post-format "status".
add_action( 'wp_footer', 'count_statuses' );
function count_statuses()
{
$status = 'status';
$num = get_term_post_count_by_type( "post-format-$status", 'post_format' );
print "<pre>{$status}es: $num</pre>";
}
/**
* Count all post in a term.
*
* @author Bainternet http://wordpress.stackexchange.com/users/2487/bainternet
* @link {http://wordpress.stackexchange.com/a/33464/73}
* @param string $term
* @param string $taxonomy
* @param string $type
* @return int
*/
function get_term_post_count_by_type( $term, $taxonomy, $type = 'post' )
{
$args = array (
'fields' =>'ids',
'posts_per_page' => -1, //-1 to get all post
'post_type' => $type,
'tax_query' => array (
array (
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term
)
)
);
if ( $posts = get_posts( $args ) )
return count( $posts );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment