#31692 closed enhancement (maybelater)
WP_Query post__in parameter to accept another WP_Query object
Reported by: | maksbd19 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
In case of constructing a query using WP_Query
class it limits the relation and matches on the posts themselves. But if the query requires to be matched from a outer domain of posts like posts those are linked with another set of posts another separate query is required.
For a clear representation of the case lets assume there are some posts with ID 1, 2, 3 and 4 which are linked with [11,12,13], [11,18,29], [12,18,19], [11,12,28,22,29] respectively (of course you can assume far more complex cases in which these posts can be retrieved by comparing some other meta values). Now using the current WP_Query class we can fetch posts that match with the desired query and by using post__in
parameter we can limit the result. For this a separate query for the linked posts is required.
I request to the community and the experts for a separate class for this parameter may be like WP_Meta_Query
so that the query class could be used in even more complicated and advanced cases.
maksbd19 - Thanks for the suggestion!
I agree that
WP_Query
has some limitations in the way that queries can be structured. In particular, query vars passed toWP_Query
are always interpreted withAND
, so thatpost__in=1,2,3&post_author=5
will only find posts that match *both* clauses.In the future, it would be nice to modify
WP_Query
so that it supports something akin to the complex, nestable syntax ofWP_Tax_Query
andWP_Meta_Query
. This will be more extensive than simply modifying the way that 'postin' works. But it will also involve major reworking ofWP_Query
, so is some way off.