[wp-trac] [WordPress Trac] #34474: sql error with wp_query and posts_per_page param
WordPress Trac
noreply at wordpress.org
Wed Oct 28 15:48:36 UTC 2015
#34474: sql error with wp_query and posts_per_page param
--------------------------+----------------------
Reporter: nicmare | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Query | Version: 4.3.1
Severity: normal | Resolution: invalid
Keywords: | Focuses:
--------------------------+----------------------
Changes (by boonebgorges):
* status: new => closed
* resolution: => invalid
* milestone: Awaiting Review =>
Comment:
Hi nicmare - Thanks for the ticket, and welcome to WordPress Trac!
It looks like you're confusing `WP_Query` by passing this enormous `$args`
array. Typically, if you want to query for all posts matching a meta query
(which I think is what you're trying to do), you'll do the following:
{{{
$q = new WP_Query( array(
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => $meta_query,
) );
}}}
`WP_Query` then calculates the rest of the necessary query vars, based on
the explicit ones you've passed.
What seems to be breaking the query in your case is that you're passing
`'nopaging' => false` along with `'posts_per_page' => -1`. Generally, if
`WP_Query` sees `'posts_per_page' => -1`, it'll set `nopaging` to `true`.
I don't think there's really anything we should do in `WP_Query` to
account for this case, where you've passed contradictory parameters. (How
would we decide which one you "really" meant?)
Thanks again for the report!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34474#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list