2famous.TV
2famous.TV

Reputation: 470

SQL SELECT multiple authors?

How do I select multiple items in my search? Here I have a list of authors that I'd like to get the categories from... but it doesn't work with commas. What do I need to do?

<?php   
$author = "4,1,909,900,970,968,5,972,969,965,971";

$categories = $wpdb->get_results("
SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug, tax.description
FROM $wpdb->posts as posts
LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
WHERE posts.post_status = 'publish' AND
    posts.post_author = '$author' AND
    tax.taxonomy = 'category'
ORDER BY terms.name ASC
");

?>

Upvotes: 0

Views: 156

Answers (1)

Anand Shah
Anand Shah

Reputation: 180

Take a Look at this question

basically you're going to need:

WHERE posts.post_author IN ($author)

Upvotes: 4

Related Questions