[wp-hackers] wp_count_posts() vs $found_posts

Chris McCoy chris at lod.com
Fri Sep 14 15:19:15 UTC 2012

$query->found_posts only show the amount found in the loop/query

wp_count_posts includes sitewide, cpts (pretty sure) etc.

-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com
[mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Kevin
Sent: Friday, September 14, 2012 9:17 AM
To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] wp_count_posts() vs $found_posts


On a vanilla Wordpress site the code at the bottom of this post works fine. 

$published_posts always equals $query->found_posts

On a site with many plugins $published_posts is correct and nonzero but
$query->found_posts is always zero and no posts are ever returned.

Does anyone have any tips for troubleshooting this type of problem? Is it
likely that a plugin is clobbering something?

$count_posts = wp_count_posts();
$published_posts = $count_posts->publish; ?>

<?php $query = new WP_Query( 'post_status=publish' ); ?> <?php print "Blog
posts: $query->found_posts"; ?><br> <?php print "Published posts:
$published_posts"; ?><br>



wp-hackers mailing list
wp-hackers at lists.automattic.com

More information about the wp-hackers mailing list