WordPress.org

Support

Support » How-To and Troubleshooting » Sorting Users by Last name

Sorting Users by Last name

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    @keesiemeijer

    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");

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

    Moderator keesiemeijer

    @keesiemeijer

    Change this:

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

    to this:

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

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sorting Users by Last name’ is closed to new replies.
Skip to toolbar