Skip Navigation

[Resuelto] User Views sorting with user_name

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
I'm using a Views to display users and wants to sort the results by user_name.
How can I do this, knowing that I found only User Name in the list of sorting fields but this is not working.

Solution:
Added the following in your theme's functions.php file:

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 == 577) {
        $query_args['meta_key'] = 'last_name';
        $query_args['orderby'] = 'meta_value';
        $query_args['order'] = 'ASC';
    }
    return $query_args;
}

==> You can replace 'last_name' with the custom field you want to use for sorting (firstname, etc) -- line #5 in the above code.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

This support ticket is created hace 7 años, 3 meses. 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Etiquetado: 

Este tema contiene 5 respuestas, tiene 2 mensajes.

Última actualización por Pat hace 7 años, 2 meses.

Asistido por: Noman.

Autor
Mensajes
#564644

Pat

Hello,

I'm using a Views to display users and wants to sort the results by user_name.
How can I do this, knowing that I found only User Name in the list of sorting fields but this is not working.
Regards
Pat

#564693

Noman
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Karachi (GMT+05:00)

sort.png

Hi Pat,

Thank you for contacting Toolset support. I have sorted the results by user_name and it is working fine at my end. See attached screenshot.

1. Can you please make sure all Toolset plugins are updated to latest versions as a primary check:
https://toolset.com/account/downloads/

2. Also can you please share your Debug Information with us so we can see it? I have enabled debug info box for your next reply:
https://toolset.com/faq/provide-debug-information-faster-support/

3. If still issue exists, could you please also try to check it by deactivating all third-party plugins and switching back to the Default Theme (e.g. Twenty Sixteen theme) to see for any possible conflicts with any of the plugins or themes?

4. Please provide back-end screenshot and front-end link where I can see the issue.

Thank you

#564725

Pat

Hi Noman,
I have foloowed your advices and the issue is still there. Here isthe code I'm using :

[wpv-layout-start]Nombre de membres actuellement : <span style="font-weight:bold;font-size:150%;">[wpv-items-count]</span></br></br>
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%">
<thead><tr>
<th>[wpv-heading name=""]ID[/wpv-heading]</th>
<th>[wpv-heading name=""]Nom[/wpv-heading]</th>
<th>[wpv-heading name=""]Prénom[/wpv-heading]</th>
<th>[wpv-heading name="user_email"]E-mail[/wpv-heading]</th>
<th>[wpv-heading name=""]Téléphone[/wpv-heading]</th>
<th>[wpv-heading name=""]Adresse[/wpv-heading]</th>

</tr></thead>
<tbody>
<wpv-loop>
<tr>
<td>[wpv-user field="ID"]</td>
<td style="text-transform:uppercase;">[wpv-user field="user_lastname"]</td>
<td>[wpv-user field="user_firstname"]</td>
<td>[wpv-user field="user_email"]</td>
<td>[wpv-user field="rpr_tlphone"]</td>
<td>[wpv-user field="rpr_adresse"]</td>

</tr>
</wpv-loop>
</tbody>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

Whatever the field chosen for the sorting condition in the Views, only the email (or the login which is the same) is working.
As this is a page which is dedicated to specific users, you will not be able to see it with the url as guest.
Regards
Pat

#564792

Noman
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Karachi (GMT+05:00)

Hello Pat,

I have checked the debug info and it looks fine. Can you please create a New View and check how it works?

If still issue persists, then I need to request temporary access (WP-Admin and FTP Login info) to your staging site.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Links to the [View] Edit Screen and [Page] Edit Screen where you have inserted this View.

Thankyou

#567614

Noman
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Karachi (GMT+05:00)

I have added the following in your theme's functions.php file:

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 == 577) {
        $query_args['meta_key'] = 'last_name';
        $query_args['orderby'] = 'meta_value';
        $query_args['order'] = 'ASC';
    }
    return $query_args;
}

Please check here, it is working as expected now:
enlace oculto

You can replace 'last_name' with the custom field you want to use for sorting (firstname, etc) -- line #5 in the above code.

Thank you

#570224

Pat

Hi Noman,

Works fine
Thanks
Pat