I am trying to: sort the users in a particular sort order as for example array(98,95,99,102) and orderby => include. So that users in a view comes in a loop starting from 98 then 95 and 99 and lastly 102 and so on.
This is my code
add_filter( 'wpv_filter_user_query', 'sort_by_lastname_func', 100, 3 );
function sort_by_lastname_func( $query_args, $view_settings, $view_id ) {
if ($view_id == 9359 ) {
$query_args['include'] = array(98,95,99,102);
$query_args['orderby'] = 'include';
}
return $query_args;
}
Instead, I got: It is sorting right now by 95,98,99,102 as ASC default order but it should sort by include parameter as supported by WordPress.
Check this screenshot: hidden link
Link to wordpress documentation is: https://codex.wordpress.org/Function_Reference/get_users
orderby and order are not the same as far I know.
You can very well orderby "include", as your experiment shows, but the order is never orderby, that is a different attribute that actually orders the orderby:
https://codex.wordpress.org/Class_Reference/WP_User_Query > Order & Orderby Parameters
So you always have an order (as or desc).
No matter what you orderby.
The order Designates the ascending or descending order of the 'orderby' parameter. Defaults to 'ASC'.
And orderby in your case is an array of ID's, so it will order them - but not by them.
I would not say this is a Tooslet Bug, but a WordPress limitation.
Can you confirm?
Hello Beda,
If you study the documentation of WordPress closely, when we orderby include, then ordering should be by the include ids listed in the array.
After trying so many things, i was able to make it work by including the order argument as neither ASC or DESC but as none.
Then the ordering by was by include ids.
I am not sure whether it is a bug in Toolset or WordPress, but still as per documentation it didnt worked out. It was just i tried order as none and it worked and nothing listed like this in wordpress documentation.
This is my general feedback as i already have it solved.
Thanks
This is not a BUG, it is exactly as I understand it to work
One is orderby (a set of values to order by) and the other is the order, to order those orderby items: Asc, Desc.
This is not just skipped.
You cannot "order" by an array of values, but only by a logic of ordering or none (hence respecting the initial sequence, no ordering at all).
I suggest to feedback or edit the WordPress Documentation if you feel it is not clear.
We do not make it, it's a volunteers and Automattics' effort:
https://codex.wordpress.org/