Created
March 20, 2012 16:00
-
-
Save NeilJS/2137474 to your computer and use it in GitHub Desktop.
WP - Get total number of posts in Custom Type Posts
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
// Put in functions.php | |
/* GET TOTAL NUMBER OF POSTS FOR SPECIFIC CUSTOM POST TYPE */ | |
function cpt_count($ptype,$display=true) { | |
global $wpdb; | |
$SQL = "SELECT count(*) FROM $wpdb->posts posts WHERE posts.post_status = 'publish' AND post_type = '".$ptype."' "; | |
$total_cpt_posts = $wpdb->get_var($SQL); | |
if($display) { | |
echo $total_cpt_posts; | |
} | |
return $total_cpt_posts; | |
} | |
// Usage | |
<?php cpt_count('case-study'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment