Wordpress SQL 查询如何 select 匹配标题正则表达式但不属于特定类别的帖子

Wordpress SQL query how to select posts that match regex for title but are not in a certain category

我可以让它在 posts that match a title and are in a category 上工作,但是我无法在 posts that match a title and are NOT in a category

上工作
select * 
from wp_posts 
join wp_term_relationships on (wp_posts.ID = wp_term_relationships.object_id)
 where (wp_term_relationships.term_taxonomy_id NOT in (107))
 and (post_title REGEXP 'video|film' ) 
 and (post_type = 'post' OR post_type = 'xdays1')
 GROUP BY wp_posts.ID

它与此具有相同数量的结果,没有任何类别代码:

select * 
from wp_posts 
WHERE
(post_title REGEXP 'video|film' ) 
 and (post_type = 'post' OR post_type = 'xdays1')
 GROUP BY wp_posts.ID

我假设我的语法有误...

我在 ID 为 107 的类别中有大约 200 个帖子。所以我希望结果不包括这些。

感谢帮助!

我认为您不需要使用“加入”。请尝试使用以下代码,看看是否可以正常工作。

SELECT wp_posts.* 
FROM wp_posts 
WHERE (wp_posts.post_title REGEXP 'video|film' )
AND ( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN (107) ) ) 
AND (wp_posts.post_type = 'post' OR wp_posts.post_type = 'xdays1') 
AND wp_posts.post_status = 'publish' 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC