2011-02-23 83 views
1

這是我現在的代碼,可以從wordpress wp_post表中獲得熱門的帖子。我如何排除3或4等類別?如何排除SQL語句中的某個類別

$popularposts = "SELECT ID,post_title FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY comment_count DESC LIMIT 0,".$pop_posts; 
$posts = $wpdb->get_results($popularposts); 
+0

這將有助於查看wp_post – Dave 2011-02-23 16:19:46

回答

1

後 '發佈' 你添加(假設categorie領域是categorie)

and categorie not in ('3', '4') 

,或者,如果categorie是數字:

and (categorie < 3 or categeorie > 4) 
1

榮登網站通過網絡和計算器,幾乎解決了這個問題。仍然需要添加

ORDER BY comment_count DESC LIMIT 0,".$pop_posts 

以下代碼中的某處。

$popularposts = "SELECT * FROM $wpdb->posts 
INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) 
INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) 

WHERE ($wpdb->term_taxonomy.term_id <> 3 
    AND $wpdb->term_taxonomy.term_id <> 4 
    AND $wpdb->term_taxonomy.taxonomy = 'category' 
    AND $wpdb->posts.post_type = 'post' 
    AND $wpdb->posts.post_status = 'publish')"; 
+0

完成的模式。 ... AND $ wpdb-> posts.post_status ='publish') ORDER BY $ wpdb-> posts.comment_count DESC LIMIT 0,「。$ pop_posts; – unigg 2011-02-23 17:17:55