• Resolved achaplin

    (@achaplin)


    I’m sure this is a quick fix–how can I sort this list alphabetically by last name?

    <?php
    $excluded = “1,3,5”; // To exclude IDs 1,3,5
    $sql = ‘SELECT DISTINCT post_author FROM ‘.$wpdb->posts. ” WHERE post_author NOT IN ($excluded)”;
    $authors = $wpdb->get_results($sql);
    if($authors):
    foreach($authors as $author):
    ?>

    Thanks so much

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think this will do what you want:

    <?php
    $excluded = "1,3,5"; // To exclude IDs 1,3,5
    $sql = "SELECT DISTINCT post_author, umeta.meta_value as last_name
    FROM $wpdb->posts
    JOIN $wpdb->usermeta umeta ON ($wpdb->posts.post_author = umeta.user_id
       AND umeta.meta_key = 'last_name')
    WHERE post_author NOT IN ($excluded)
    AND post_status = 'publish'
    AND post_type = 'post'
    ORDER BY last_name, post_author
    ";
    $authors = $wpdb->get_results($sql);
    if($authors):
       foreach($authors as $author):
    Thread Starter achaplin

    (@achaplin)

    Thank you so much, this is exactly what I needed!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Author's List Order by last name’ is closed to new replies.