• Above is the code in directory.php from the Helper Fields add on which orders the directory by the date the user registered. I need to order it by last name. Can anyone help me crack this nut?

    $sqlQuery = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, u.user_nicename, u.display_name, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id WHERE mu.status = 'active' AND mu.membership_id > 0 AND ";
    
    		if(empty($key))
    			$sqlQuery .= "(u.user_login LIKE '%$s%' OR u.user_email LIKE '%$s%' OR u.display_name LIKE '%$s%' OR um.meta_value LIKE '%$s%') ";
    		else
    			$sqlQuery .= "(um.meta_key = '" . $wpdb->escape($key) . "' AND um.meta_value LIKE '%$s%') ";
    
    		if($level)
    			$sqlQuery .= " AND mu.membership_id IN(" . $level . ") ";					
    
    		$sqlQuery .= "GROUP BY u.ID ORDER BY user_registered DESC LIMIT $start, $limit";
    	}
    	else
    	{
    		$sqlQuery = "SELECT SQL_CALC_FOUND_ROWS u.ID, u.user_login, u.user_email, u.user_nicename, u.display_name, UNIX_TIMESTAMP(u.user_registered) as joindate, mu.membership_id, mu.initial_payment, mu.billing_amount, mu.cycle_period, mu.cycle_number, mu.billing_limit, mu.trial_amount, mu.trial_limit, UNIX_TIMESTAMP(mu.startdate) as startdate, UNIX_TIMESTAMP(mu.enddate) as enddate, m.name as membership FROM $wpdb->users u LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id";
    		$sqlQuery .= " WHERE mu.membership_id > 0  AND mu.status = 'active' ";
    		if($level)
    			$sqlQuery .= " AND mu.membership_id IN(" . $level . ") ";
    		$sqlQuery .= "ORDER BY user_registered DESC LIMIT $start, $limit";
    	}

    https://www.ads-software.com/plugins/paid-memberships-pro/

Viewing 1 replies (of 1 total)
  • Unfortunately these forums aren’t getting a lot of love lately – and your question probably needs to be directed to the paid support forums. (I’m not associated with the plugin developers, I only try to answer questions here when I can, based on our use of PMPro.)

    I think the whole query needs to be changed to do a JOIN to wp_usermeta and then sort by the meta key last_name – it’s not just about changing one reference in the existing code.

Viewing 1 replies (of 1 total)
  • The topic ‘Sort directory by member last name’ is closed to new replies.