[wp-hackers] Multiple orderby and order options in WP_Query

scribu mail at scribu.net
Tue Apr 5 17:33:52 UTC 2011


On Tue, Apr 5, 2011 at 7:28 PM, Otto <otto at ottodestruct.com> wrote:

> Can't do it with a naive WP_Query. Use the posts_orderby filter to add
> your own ordering string.
>
> function my_order($orderby) {
> global $wpdb;
> return "{$wpdb->posts.post_author} ASC, {$wpdb->posts.post_date} DESC";
> }
>
> add_filter( 'posts_orderby', 'my_order' );
> $blah = new WP_Query(...);
> remove_filter( 'posts_orderby', 'my_order' );
>


Yeah, except remove_filter() will remove all callbacks attached to
posts_orderby, due to this bug:

http://core.trac.wordpress.org/ticket/9968

-- 
http://scribu.net


More information about the wp-hackers mailing list