2011-02-23 76 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