0
votes

Hi I’m trying to order entries by a field called surname but it just doesn’t seem to be working. changing orderby and sort to anything gives the same results - latest entry last in list.

Any ideas what I could be doing wrong?

{exp:query sql="SELECT member_id FROM exp_members WHERE group_id = '5'"}
{exp:member:custom_profile_data  member_id="{member_id}" orderby="surname" sort="asc"}
<li><a href="{path=portfolios/gallery/{username}}"><img src="{photo_url}" width="138" height="103" alt="{screen_name}" /></a>
<h3 class="name"><a href="{path=portfolios/gallery2/{username}}">{firstname} {surname}</a></h3></li>
{/exp:member:custom_profile_data} 
{/exp:query} 
2

2 Answers

1
votes

To save yourself some energy you might want to think about using Freemember from Exp-resso on your site. https://github.com/expressodev/freemember

This module has super simple syntax to do what you are wanting and might add some additional features to make your ExpressionEngine development easier.

0
votes

I'll start by pointing out that if you have a lot of members, this nested query could really bog down your server. It would be much more efficient to use the Query module to get all of your member data in one go, then interate through it without the nested custom_profile_data tag. You'd have to account for variables that get manipulated beforehand using custom_profile_data (like image URLs), but it would be worth the effort in performance gains.

Regardless:

The custom_profile_data tag only queries a single member, so orderby and sort won't make any difference. Your sorting needs to take place during your exp:query tag.

{exp:query sql="SELECT m.member_id FROM exp_members m, exp_member_data d WHERE m.group_id = '5' AND d.member_id = m.member_id ORDER BY d.m_field_id_X ASC"}
{exp:member:custom_profile_data  member_id="{member_id}"}
    <li><a href="{path=portfolios/gallery/{username}}"><img src="{photo_url}" width="138" height="103" alt="{screen_name}" /></a>
    <h3 class="name"><a href="{path=portfolios/gallery2/{username}}">{firstname} {surname}</a></h3>
    </li>
{/exp:member:custom_profile_data} 
{/exp:query}

Replace m_field_id_X with the actual m_field_id of your surname custom member field (which can be found by looking at exp_member_fields in Tools → Data → SQL Manager).