[wp-hackers] wp-hackers Digest, Vol 92, Issue 14

Kevin Ladenheim kplad21230 at yahoo.com
Sat Sep 15 13:20:29 UTC 2012


Thanks for the reply. Some more detail: the site only has 8 published posts. 

The codex says:

   Get the Publish Status Post Count
   To get the published status type, you would call the wp_count_posts() function and then access the 'publish' property.
       $count_posts = wp_count_posts(); 
       $published_posts = $count_posts->publish; 

So there are only 8 published posts. $published_posts is 8 but the WP_Query below is not returning any results:
$query->found_posts = 0

Any idea how that could happen?

$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>

Thanks a lot,



Message: 2
Date: Fri, 14 Sep 2012 11:19:15 -0400
From: "Chris McCoy" <chris at lod.com>
Subject: Re: [wp-hackers] wp_count_posts() vs $found_posts
To: <wp-hackers at lists.automattic.com>
Message-ID: <000401cd928c$4d77dc70$e8679550$@lod.com>
Content-Type: text/plain;    charset="iso-8859-1"

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

wp_count_posts includes sitewide, cpts (pretty sure) etc.

More information about the wp-hackers mailing list