[wp-trac] [WordPress Trac] #30982: Meta query in pre_get_posts
WordPress Trac
noreply at wordpress.org
Mon Jan 12 16:41:22 UTC 2015
#30982: Meta query in pre_get_posts
-----------------------------+------------------------------------
Reporter: Spidlace | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Future Release
Component: Query | Version: 4.1
Severity: major | Resolution:
Keywords: | Focuses: template, performance
-----------------------------+------------------------------------
Changes (by boonebgorges):
* milestone: Awaiting Review => Future Release
Comment:
Short answer: No, you can't do this. It would be nice if you could, but it
would take major reworking of `WP_Query`.
Longer answer: Query vars passed to `WP_Query` are translated into
independent SQL clauses, all of which are joined by `AND`. The API does
not support connecting them with `OR`. I have a pie-in-the-sky idea that
we should adopt the recursive syntax of `WP_Meta_Query` etc, so that you
could nest query conditions and connect them with the relation of your
choice, kinda like this:
{{{
$q = new WP_Query( array(
'relation' => 'OR',
array(
'relation' => 'AND',
'post__in' => array( 5,6,7 ),
's' => 'foo',
),
array(
'relation' => 'AND',
'meta_query' => $meta_query,
'post_parent__in' => array( 8,9,10 ),
),
) );
}}}
etc etc etc. But this would require an extensive rewrite of
`WP_Query::get_posts()`.
For now, I recommend doing a direct SELECT query to get a list of posts
that match your 'exemple' search terms (you can use `WP_Meta_Query` to
help build the SQL), and then pass the resulting IDs to `post__in` in your
'pre_get_posts' filter.
Related: #16910, #15068
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30982#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list