[wp-trac] [WordPress Trac] #23833: Add a unique ID or NAME to target queries .

WordPress Trac noreply at wordpress.org
Mon May 6 15:00:06 UTC 2013


#23833: Add a unique ID or NAME to target queries .
-------------------------+------------------------------
 Reporter:  krembo99     |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |
-------------------------+------------------------------

Comment (by prettyboymp):

 Sorry it took me so long to get back to this.  After going back and
 reading my first post, I realized my response is a bit confusing because
 I'm addressing multiple issues I have with WP_Query as it is, though
 they're are all related to this ticket.

 I don't have a direct issue with adding 'context' as a query_var.  I agree
 that it is probably the best way for a plugin to know how to alter a
 specific query.  But I believe it should only be allowed as an
 intermediate query_var.  A query_var like 'context' should be converted
 into one or more query_vars that explicitly express the filters they are
 adding to the query result.  Without that conversion, any plugin that may
 replace the request to WPDB with some other backend, like a search
 provider, has no way to reimplement the logic added by a plugin that
 directly altered the MySQL query based on 'context'.  However, if the
 plugin took {'context' => 'sidebar'} and converted it into {'meta_key' =>
 'feature_sidebar', 'meta_value' => '1'}, other plugins could understand
 it.

 An example implementation would be.

 {{{
 $my_query = get_query(array('context'=> 'sidebar', 'posts_per_page' =>
 5));

 function get_query($args) {
     $query_vars = apply_filters('parse_query_vars', $args); //allows
 plugins to translate 'context' into explicit query vars
     ....//core code taken out of WP_Query to fill in any unset with
 defaults
     return new WP_Query($query_vars);
 }
 }}}

 With the above, WP_Query would be changed so that it only paid attention
 to explicit query vars.  It wouldn't know what to do with something like
 'context' since 'context' has no applicable meaning.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23833#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list