Hey @duellingpixels,
I using the plugin with the shortcode, what would be the best way to change the order of the output in the user-taxonomy-template file?
What order you want for the users? Alphabetically or some other logic?
You can try using the filter ut_template_users, you can find it in here:
https://plugins.trac.ww.wp.xz.cn/browser/user-tags/trunk/templates/user-taxonomy-template.php#L26
If this doesn’t help, I’d be happy to help you in any possible manner.
Cheers
Hi Umesh,
Thanks for getting so quick.
Yep, had found this so it must be the my filter that is wrong. I was using:
function ut_template_users( $users) {
$allUsers = get_users(‘orderby=display_name’);
// very basic comparison…
return $allUsers;
}
I was looking at sorting out the user list by first name, I think adding a basic example to the FAQ would be a great idea. Than other folk can use it to adjust to their requirements.
Cheers.
Nick
Here you go Nick,
add_filter( 'ut_template_users', 'ut_sort_users' );
/**
* Filters out the list of users in a template, and orders it by user_login
*
* @param $users
*
* @return mixed
*/
function ut_sort_users( $users ) {
if ( empty( $users ) || ! is_array( $users ) ) {
return $users;
}
$user_query = new WP_User_Query( array( 'fields' => 'ID', 'include' => $users, 'orderby' => 'user_login' ) );
if ( ! is_wp_error( $user_query ) && ! empty( $user_list = $user_query->get_results() ) ) {
return $user_list;
}
return $users;
}
I’ve added the same in FAQ as well, but it seems, it’ll be visible only after next release, or version bump.
Hope this works
Hi Umesh,
Thanks for share the code, I was way off.
I tried this code and I seem to get a fetal error on the line:
PHP Parse error: syntax error, unexpected ‘=’, expecting ‘)’ in /home/creativeplatoon/public_html/developer/wp-content/themes/thegreenman/functions.php on line 1125
Any ideas?
Cheers,
Nick
Apologies, I should of stated that is line:
if ( ! is_wp_error( $user_query ) && ! empty( $user_list = $user_query->get_results() ) ) {
(my bad!)
Cheers,
Nick
Um, this should work:
add_filter( 'ut_template_users', 'ut_sort_users' );
/**
* Filters out the list of users in a template, and orders it by user_login
*
* @param $users
*
* @return mixed
*/
function ut_sort_users( $users ) {
if ( empty( $users ) || ! is_array( $users ) ) {
return $users;
}
$user_query = new WP_User_Query( array( 'fields' => 'ID', 'include' => $users, 'orderby' => 'user_login' ) );
$user_list = $user_query->get_results();
if ( ! is_wp_error( $user_query ) && ! empty($user_list) ) {
return $user_list;
}
return $users;
}
Hey Umesh,
Perfect!! Thank you so much!
Cheers,
Nick