[wp-trac] [WordPress Trac] #29178: Using WP_Query only for result of SQL_CALC_FOUND_ROWS
WordPress Trac
noreply at wordpress.org
Fri Feb 13 16:47:07 UTC 2015
#29178: Using WP_Query only for result of SQL_CALC_FOUND_ROWS
-----------------------------+-----------------------------
Reporter: danielbachhuber | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Query | Version:
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
-----------------------------+-----------------------------
Comment (by boonebgorges):
danielbachhuber - Yes, I think that's the gist of it.
As a workaround, you can do the following:
{{{
$q = new WP_Query( array(
'fields' => 'ids',
'posts_per_page' => -1,
'no_found_rows' => true,
) );
$count = count( $q->posts );
}}}
I'm not sure how much overhead this adds beyond `SELECT COUNT(*)`. A
little extra memory is required to store the post IDs.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29178#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list