[wp-trac] [WordPress Trac] #60490: Add 'author__in' option to WP_Query 'orderby' options

WordPress Trac noreply at wordpress.org
Fri Feb 9 21:34:45 UTC 2024


#60490: Add 'author__in' option to WP_Query 'orderby' options
-----------------------------+------------------------------
 Reporter:  bburgay          |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Query            |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by bburgay):

 I was able to solve this with the posts_orderby filter too so figured I'd
 add it here in case anyone else needs it for now.


 {{{
 function orderby_author__in($orderby, $query) {
   if (!empty($query->query_vars['author__in'])) {
         global $wpdb;
         $orderby = "FIELD({$wpdb->posts}.post_author," . implode(',',
 array_map('absint', $query->query_vars['author__in'])) . ')';
   }
   return $orderby;
 }
 add_filter('posts_orderby', 'orderby_author__in', 10, 2);
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60490#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list