WordPress.org

Ready to get started?Download WordPress

Forums

Sorting Users by Last name (5 posts)

  1. jonahrbrown
    Member
    Posted 1 year ago #

    I am creating a Member list and want to be able to sort it by last name.

    my code is here: http://pastebin.com/mH0eiJVT

    What can I do to adjust this?

    Jonah

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with this:

    global $wpdb;
    $wp_user_search = $wpdb->get_results("SELECT user_id, meta_value FROM $wpdb->usermeta WHERE $wpdb->usermeta.meta_key = 'last_name' ORDER BY $wpdb->usermeta.meta_value ASC");
  3. jonahrbrown
    Member
    Posted 1 year ago #

    ok it made the rows in the table, but I see no data output. Am I missing something here?

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Change this:

    $user_id = (int) $userid->ID;

    to this:

    $user_id = (int) $userid->user_id;
  5. jonahrbrown
    Member
    Posted 1 year ago #

    Ok that is some what working. So the part i am figuring out is the other data not showing up.

    Specifically: Spouse, Last name & Phone.

    I used s2memebers for some of the user meta. I am planning a better method later this year using User Meta plugin or Gravity forms user resgistration plugin.

    Most of the members did not fill in the last name and only used family surname.

    if($family_surname <> ''){
    	        	echo '<td>'. $family_surname . '</td>';
    	        } else{
    		    	echo '<td>'. $last_name . '</td>';
    
    	        }

    which is what that statement is doing there. so I am wondering if the query can be adjusted to include checking this?

    Sorry I am new if this area of programming. I know php but wordpress database statements tend to make my head turn.

    Thanks for your help in getting this solved.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.