本文介绍了获取除一个类别以外的所有类别的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在搜索时,我希望所有类别的所有帖子(一个类别除外)
这是我的搜索查询
SELECT * FROM wp_posts WHERE post_title like '%$search%' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC
在此查询中,我不希望 book 个类别的帖子.当我搜索任何关键字时,需要显示除 book 类别帖子
In this query, i don't want book category posts. when i search any keyword, need to display all posts except book category posts
有帮助吗?
推荐答案
尝试以下方法:-
14是类别ID
$request = $wpdb->prepare("SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE ($wpdb->term_taxonomy.term_id <> 14
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
AND post_title like '%$search%'
AND post_date >= '" . date('Y-m-d').")");
这篇关于获取除一个类别以外的所有类别的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!