[wp-trac] [WordPress Trac] #12731: Add a callback to get_posts() in /wp-includes/query.php to enable more robust plugins

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 27 10:56:35 UTC 2010


#12731: Add a callback to get_posts() in /wp-includes/query.php to enable more
robust plugins
--------------------------+-------------------------------------------------
 Reporter:  mikeschinkel  |       Owner:  ryan      
     Type:  enhancement   |      Status:  new       
 Priority:  normal        |   Milestone:  Unassigned
Component:  Query         |     Version:  3.0       
 Severity:  normal        |    Keywords:            
--------------------------+-------------------------------------------------

Comment(by mikeschinkel):

 I just noticed a bug in my example use-case:
 {{{
   add_filter('get_posts_callback_add_tax_terms','my_add_tax_terms',10,3);
   $q = new
 WP_Query('post_type=session&posts_per_page=9999&callback=add_tax_terms');
   foreach($q->posts as $post) {
     echo "{$post->post_title}: {$post->taxonomy_terms}\n";
   }

 function my_add_tax_terms( $value,$query,$tag ) {
   global $wpdb;
   switch($tag) {
     case 'posts_fields':
       $value .= ',taxonomy_terms.taxonomy_terms';
       break;
     case 'posts_join':
       $value .= " LEFT OUTER JOIN (SELECT $wpdb->posts.ID AS post_ID,
 GROUP_CONCAT(CONCAT_WS('/',$wpdb->term_taxonomy.taxonomy,$wpdb->terms.slug)
         ORDER BY $wpdb->terms.name SEPARATOR ',')
           AS taxonomy_terms FROM $wpdb->posts
         LEFT OUTER JOIN $wpdb->term_relationships ON
           $wpdb->term_relationships.object_id=$wpdb->posts.ID
         LEFT OUTER JOIN $wpdb->term_taxonomy ON
 $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
         LEFT OUTER JOIN $wpdb->terms ON
           $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id
         WHERE 1=1 GROUP BY $wpdb->posts.ID) taxonomy_terms
           ON $wpdb->posts.ID=taxonomy_terms.post_ID ";
       break;
   }
 return $value;
 }
 }}}

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


More information about the wp-trac mailing list