• Hey there, I am a MySQL newbie (but ok at php) and I found a custom query online to create a list of all site users. I modified it to show only the users whose birthday is this month (‘birthday’ and ‘birthmonth’ are custom fields I added to the usermeta table.) It displays great, the only thing I can’t get it to do is sort by birthday (day of the month, a number.) Right now it’s sorting by first name. Can anyone help? Here is the code:

    `$userSort = “birthday”;
    $aUsersID = $wpdb->get_col( $wpdb->prepare(
    “SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC”
    , $userSort ));
    $current_month = get_the_time(‘n’);
    $current_day = get_the_time(‘j’);
    foreach ($aUsersID as $iUserID) :
    $user = get_userdata($iUserID);
    if ($user->birthmonth == $current_month) :
    echo ‘

Viewing 1 replies (of 1 total)
  • Thread Starter semidivine

    (@semidivine)

    hey my backticks didn’t prevent the link from messing it up… let me try this again. that echo is:

    echo ‘[li][a href=”/?author=’.$iUserID.'”]’.ucwords(strtolower($user->first_name.’ ‘.$user->last_name.'[/a] (‘.$user->birthmonth.’/’.$user->birthday)).’)[/li]
    ‘;

Viewing 1 replies (of 1 total)
  • The topic ‘Help with a custom query: how to sort by a usermeta field’ is closed to new replies.