[wp-hackers] WP User Query sorting

Dobri dyordan1 at ramapo.edu
Tue Aug 6 20:39:53 UTC 2013


Hey,

why no love for the WP_User_Query ordering? I've noticed that you can specify meta key ordering for WP_Query but not for WP_User_Query. Would there be an easy way to do sorting on user meta then? Without doing a lot of SQL-level stuff? Posted below is what I currently have, which doesn't really work.. duh. Any help appreciated! Thanks!

========================================

function user_custom_column_orderby( $query )
{
    $vars = $query->query_vars;
    if ( isset( $vars['orderby'] ) && ('my_meta1' == $vars['orderby'] || 'my_meta2' == $vars['orderby'] || 'my_meta3' == $vars['orderby'] ) ) {
        $vars = array_merge( $vars, array(
            'meta_key' => $vars['orderby'],
            'orderby' => 'meta_value_num'
        ) );
    }
    $query->query_vars = $vars;

    return $query;
}
add_filter( 'pre_user_query', 'user_custom_column_orderby' );

========================================

P.S. I also noticed this pesky guy in the WP_User_Query object:
public 'query_orderby' => string 'ORDER BY user_login ASC' (length=23)
Do I have to worry about it?

~Dobri



More information about the wp-hackers mailing list