0
如何在我的搜索中選擇多個項目?在這裏,我有一個作者列表,我想從中獲取類別...但它不適用於逗號。我需要做什麼?SQL SELECT多位作者?
<?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
");
?>
太謝謝你了!我對SQL很陌生,所以有人通過這些令人討厭的初學者顛簸,這是非常好的,因爲它會佔用很多不必要的時間。 –
@ 2famous.TV如果你發現這個答案解決了你的問題,然後接受它 –
啊......很酷!我對此很陌生,並且感到困惑,我不允許上下投票。接受也很酷:) –