1
我正在修改一個wordpress插件(相關文章的分類),使它成爲「分類學相關文章」。我創建了多個分類(元素,顏色和心情),我希望將其包含在此查詢中,但似乎只能使其與一個分類(元素)一起工作。下面的代碼只返回具有相同「元素」的相關帖子。我究竟做錯了什麼?我希望代碼能夠返回匹配一個,兩個或所有分類法的帖子,而不僅僅是元素。查詢多個分類標準
$posts = $GLOBALS['wpdb']->get_results(
sprintf(
"SELECT DISTINCT object_id as ID, post_title
FROM {$GLOBALS['wpdb']->term_relationships} r, {$GLOBALS['wpdb']->term_taxonomy} t, {$GLOBALS['wpdb']->posts} p
WHERE t.term_id IN (SELECT t.term_id FROM {$GLOBALS['wpdb']->term_relationships} r, {$GLOBALS['wpdb']->term_taxonomy} t
WHERE r.term_taxonomy_id = t.term_taxonomy_id
AND t.taxonomy = 'elements'
AND r.object_id = $id)
AND r.term_taxonomy_id = t.term_taxonomy_id
AND p.post_status = 'publish'
AND p.ID = r.object_id
AND object_id <> $id %s %s %s",
($type ? ("AND p.post_type = '" .$type. "'") : ''),
($orderby ? ('ORDER BY ' .(strtoupper($params['orderby']) == 'RAND' ? 'RAND()' : $orderby. ' ' .$order)) : ''),
($limit ? ('LIMIT ' .$limit) : '')
)
謝謝!這工作完美! – Natasha 2010-07-07 15:24:41