WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#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.

Change History (2)

#1 @boonebgorges
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

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 to WP_Query are always interpreted with AND, so that post__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 of WP_Tax_Query and WP_Meta_Query. This will be more extensive than simply modifying the way that 'postin' works. But it will also involve major reworking of WP_Query, so is some way off.

#2 @DrewAPicture
4 years ago

  • Summary changed from WP_Query post__in parameter to accept another WP_Query objcet to WP_Query post__in parameter to accept another WP_Query object
Note: See TracTickets for help on using tickets.