0

如何在搜索中选择多个项目?在这里,我有一个作者列表,我想从中获取类别......但它不适用于逗号。我需要做什么?

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

?>
4

1 回答 1

4

看看这个问题

基本上你将需要:

WHERE posts.post_author IN ($author)
于 2013-07-02T13:32:18.070 回答