在搜索时,我想要除了一个类别
以外的所有类别的所有帖子这是我的搜索查询
SELECT * FROM wp_posts WHERE post_title like '%$search%' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC
在此查询中,我不想要图书类别帖子。当我搜索任何关键字时,需要显示除 book 类别帖子
之外的所有帖子有任何帮助吗?
答案 0 :(得分:0)
请尝试以下方法: -
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').")");