[wp-trac] [WordPress Trac] #25193: Introduce "scope" query_var to be used in WP_Query

WordPress Trac noreply at wordpress.org
Fri Aug 30 16:00:55 UTC 2013


#25193: Introduce "scope" query_var to be used in WP_Query
----------------------------+-------------------------
 Reporter:  wonderboymusic  |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  3.7
Component:  Query           |    Version:  trunk
 Severity:  normal          |   Keywords:  needs-patch
----------------------------+-------------------------
 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
 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.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25193>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list