I want to manipulate the order of WP_User_Query()
. I want the user to come out ordered by a custom meta field and by ascending order.
I have the code correctly working tested it on users.php
but since this is not a good place to put it I wanted to run add_filter( 'prepare_query', 'my_prepare_query');
The call in the theme (‘include’ doesn’t exist):
$count_args = array(
'include' => $include,
'number' => 999999,
'fields' => 'ID',
'orderby' => 'include',
'order' => 'ASC'
);
$user_count_query = new WP_User_Query( $count_args );
I just simply added another elseif
to prepare_query
on line 433 of user.php
:
elseif ( 'include' == $qv[ 'orderby' ] ) {
$this->query_from .= " INNER JOIN wp_usermeta ON wp_usermeta.user_id = $wpdb->users.ID";
$this->query_where .= " AND wp_usermeta.meta_key = 'my_userpoints'";
$orderby = "wp_usermeta.meta_value";
}
Now why is the add_filter
not overwriting the user.php
function? Is it not possible to overwrite core functions?
The
WP_User_Query
allowsmeta_query
searches exactly like the otherWP_*_Query
classes. Example here: