Created
March 18, 2013 09:49
-
-
Save thefuxia/5186068 to your computer and use it in GitHub Desktop.
Count posts in post-format "status".
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
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