Opened 11 years ago
Closed 10 years ago
#25193 closed defect (bug) (maybelater)
Introduce "scope" query_var to be used in WP_Query
Reported by: | wonderboymusic | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.8 |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
After combing through a bunch of tickets, there seems to be a need for scoping queries to an initial WHERE
condition.
Examples:
does the post have a password? or not? #20308
does the post have comments? or not? #25180
Rather than adding an endless number of new query vars for each case, maybe we should add one query_var: scope
and add cases to it.
Scope is present in Active Record in Rails: http://guides.rubyonrails.org/active_record_querying.html#scopes, which is what made me think of this.
Something like:
$query = new WP_Query( array( 'post_author' => 3, 'scope' => 'has_comments' ) );
Perhaps even multiple:
$query = new WP_Query( array( 'post_author' => 3, 'scope' => 'has_comments,password_protected' ) );
or
$query = new WP_Query( array( 'post_author' => 3, 'scope' => array( 'has_comments', 'password_protected' ) ) );
I will add an example patch later today.
Attachments (1)
Change History (9)
Note: See
TracTickets for help on using
tickets.
implemented in 25193.diff - this would squash the need for #20308 or #25180. Added unit tests and fixed the horrendous whitespace on the
post/query.php
unit tests.