WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Author's List Order by last name (3 posts)

  1. achaplin
    Member
    Posted 2 years ago #

    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

  2. vtxyzzy
    Member
    Posted 2 years ago #

    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):
  3. achaplin
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic