Make WordPress Core

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's profile 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)

25193.diff (30.1 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (9)

#1 @ryanduff
11 years ago

  • Cc ryan@… added

#2 @wonderboymusic
11 years ago

  • Keywords has-patch added; needs-patch removed

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.

#3 @DrewAPicture
11 years ago

  • Cc xoodrew@… added

#4 @johnbillion
11 years ago

  • Cc johnbillion added

#5 @toscho
11 years ago

  • Cc info@… added

#6 @wonderboymusic
10 years ago

  • Milestone changed from 3.7 to Future Release

This did not receive the love I hoped

#7 @buffler
10 years ago

  • Cc jeremy.buller@… added

#8 @wonderboymusic
10 years ago

  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from new to closed

I opened this, I will reopen later if my future self decides it is worthwhile.

Note: See TracTickets for help on using tickets.