What the heck is going on, you ask? Say hello to Tersus.

Bare bones? You got it. Tersus is an achingly simple WordPress theme without all the usual cruft.

Super Ginormous

This is the personal site/blog/experiment of Chris Harrison, a web designer living, working and playing in Augusta, GA.

Archive for July, 2010

How to display total number of Custom Posts on a WordPress site

Tuesday, July 27th, 2010

Based on this quick tip from WPRecipes, I was able to quickly figure out how to count and display the number of Custom Posts (of a particular type) that I had on a site.

<?php
	$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE (post_status = 'publish' AND post_type = 'listing')");
	if (0 < $numposts) $numposts = number_format($numposts);
?>

Simply replace post_type = 'listing' with whatever you’ve named your custom post type. Then, to get the number to display somewhere on your page, simply insert the following code where appropriate:

<?php echo $numposts ?>

Categories:

3 Comments