achaplin
Member
Posted 8 months 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
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):
achaplin
Member
Posted 8 months ago #
Thank you so much, this is exactly what I needed!