Skip Navigation

[Resuelto] User view not displaying "Last Name" in "Ordering"

This support ticket is created hace 7 años, 1 mes. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Etiquetado: ,

Este tema contiene 5 respuestas, tiene 2 mensajes.

Última actualización por marcB-6 hace 7 años, 1 mes.

Asistido por: Luo Yang.

Autor
Mensajes
#577362
Screenshot_37.png

I am trying to display users order by "Last Name".
I have created view to display users.
I expected to see "Last Name" in "Ordering" dropdown in view.

In "Ordering" dropdown I can not see "Last Name" field.See screenshot

Thanks.

#577542
lastname.JPG

Dear Marc,

Thanks for the feedback, as you can see, there isn't such an option to order the user view by user's last name field, but you can override the "orderby" settings with some custom codes by using filter hook "wpv_filter_user_query".

For example, you can try this:
1) edit the user view, in section "Query Filter", add a filter:
Select items with field:
last_name is a string different from
see screenshot lastname.JPG

2) Add below codes into your theme/functions.php:

add_filter('wpv_filter_user_query', 'my_func1', 999, 3);
function my_func1($query_args, $view_settings, $view_id){
	if($view_id != 123)return $query_args;
	$query_args['orderby'] = 'meta_value';
	$query_args['order'] = 'ASC';
	return $query_args;
}

Please replace 123 with your user view's ID, and test again.

More help:
wpv_filter_user_query
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query
Order & Orderby Parameters
https://codex.wordpress.org/Class_Reference/WP_User_Query#Order_.26_Orderby_Parameters

#577546

I have added above code but it doesn't seems to be working here : enlace oculto look at "Delegates" section. Users are not sorted by last name.

Also, the filter you gave is creating problem with my other view, In that it is not showing user at all here : enlace oculto

If I remove filter from functions.php file it is showing users here : enlace oculto

Thanks

#577551

I have already modified above codes, and tested it in my localhost, it works fine, and it is only an example, you will need to customize it according to your website, if you still need assistance for it, please provide a test site with same problem, and fill below private detail box with login details and ftp access, also point out where I can edit your PHP codes, I need a live website to test and debug it, thanks

#577563

Thanks for the details, I assume the problem page is this one:
enlace oculto

And I have modified the PHP codes as below, please test again, check if it is fixed.

add_filter('wpv_filter_user_query', 'my_func1', 999, 3);
function my_func1($query_args, $view_settings, $view_id){
    if($view_id != 489)return $query_args;
    $query_args['orderby'] = 'meta_value';
    $query_args['order'] = 'ASC';
    $query_args['meta_key'] = 'last_name';
    return $query_args;
}

More help:
https://codex.wordpress.org/Class_Reference/WP_User_Query#Order_.26_Orderby_Parameters
'meta_value' - Note that a 'meta_key=keyname' must also be present in the query

#577574

Thanks