[wp-trac] [WordPress Trac] #4065: useful function: merge_wp_queries()

WordPress Trac wp-trac at lists.automattic.com
Tue Feb 1 08:39:09 UTC 2011


#4065: useful function: merge_wp_queries()
-----------------------------+-----------------------------
 Reporter:  markjaquith      |       Owner:  anonymous
     Type:  feature request  |      Status:  new
 Priority:  low              |   Milestone:  Future Release
Component:  Optimization     |     Version:
 Severity:  minor            |  Resolution:
 Keywords:  needs-patch      |
-----------------------------+-----------------------------

Comment (by mikeschinkel):

 Replying to [ticket:4065 markjaquith]:
 > It would be really handy if you could take two WP_Query objects and
 merge them.  Duplicate posts would be removed, and you could choose a sort
 column and sort order.
 >
 > Example usage:
 >
 > {{{
 > $q1 = new WP_Query('monthnum=12&year=2006');
 > $q2 = new WP_Query('monthnum=1&year=2007');
 > $merged = merge_wp_queries($q1, $q2, 'post_date_gmt', 'desc');
 > }}}

 Are you envisioning to merge the results after two queries are run, or
 merge the SQL and only run one query?  Looks like the former but isn't
 that just an array merge?

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


More information about the wp-trac mailing list