0

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
");

?>
2famous.TV
  • 460
  • 1
  • 6
  • 23

1 Answers1

4

Take a Look at this question

basically you're going to need:

WHERE posts.post_author IN ($author)
Community
  • 1
  • 1
Anand Shah
  • 180
  • 5
  • Thank you so much! I'm quite new to SQL-ing, so it's very nice to have someone pass these annoying beginners bumps that takes up so much unnecessary time. – 2famous.TV Jul 02 '13 at 13:54
  • @2famous.TV if you find this answered as solved your problem then accept it – M Khalid Junaid Jul 02 '13 at 16:18
  • Ahh... cool! I'm new to this, and was puzzled that I'm not allowed to vote up and down. Accepting is pretty cool too :) – 2famous.TV Jul 03 '13 at 07:58