这是我目前从wordpress wp_post表中获取热门帖子的代码。如何排除3或4类别中的那些?
$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 :(得分:1)
在'发布'之后添加(假设类别的字段是类别)
and categorie not in ('3', '4')
或者,如果类别是数字:
and (categorie < 3 or categeorie > 4)
答案 1 :(得分: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')";