• Resolved eian00

    (@eian00)


    How can you list all users that have the last name starting with the letter A?

    List the Last name, and next to it his first name

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • vtxyzzy

    (@vtxyzzy)

    Here is some sample code that does what you want:

    $sql = "SELECT umfirst.meta_value AS first_name, umlast.meta_value AS last_name
    FROM $wpdb->usermeta umfirst, $wpdb->usermeta umlast
    WHERE umlast.meta_key = 'last_name'
    AND umfirst.meta_key = 'first_name'
    AND umfirst.user_id = umlast.user_id
    AND umlast.meta_value LIKE 'A%'";
    
    $rows = $wpdb->get_results($sql);
    foreach ($rows as $row) {
      echo "$row->last_name, $row->first_name<br />";
    }
    ?>
    Thread Starter eian00

    (@eian00)

    Nice it works,

    I would need now just a more complex form;

    next to the last and first name, display also the cimy field value, under the label “status”, and all together make a link to the users author.php page.

    Thank you

    vtxyzzy

    (@vtxyzzy)

    Before I work on that, I want to make sure that is all you want. Is there more?

    Thread Starter eian00

    (@eian00)

    I am exercising on that right now, so it is just perfect your solution on the top.

    Thank you again

    vtxyzzy

    (@vtxyzzy)

    Here is code for you to try:

    // List authors by first letter of last name
    $sql = "SELECT umfirst.user_id, umfirst.meta_value AS first_name, umlast.meta_value AS last_name
    FROM $wpdb->usermeta umfirst, $wpdb->usermeta umlast
    WHERE umlast.meta_key = 'last_name'
    AND umfirst.meta_key = 'first_name'
    AND umfirst.user_id = umlast.user_id
    AND umlast.meta_value LIKE 'A%'
    ORDER BY last_name, first_name";
    
    $rows = $wpdb->get_results($sql);
    foreach ($rows as $row) {
      $cimy_value = get_cimyFieldValue($row->user_id, 'PHONE');
      $user_data =  "$row->last_name, $row->first_name $cimy_value";
      if (is_user_logged_in()) {
        $output = "<a href=\"" . get_bloginfo('url') . '/wp-admin/user-edit.php/?user_id=' . $row->user_id  . '" alt="" >' . $user_data . '</a>';
      } else {
        $output = $user_data;
      }
      echo "$output<br />\n";
    }

    (note to self: from miataclub29 testphp.php)

    @vtxyzzy
    I’m not understanding your code. Does it go in a template file wrapped by <?php> tags or in the functions file?

    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘List all users by first letter in name’ is closed to new replies.