wordpress搜索查询不工作

goucqfw6  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(248)

我试图弄清楚为什么这个查询返回所有post类型,而不仅仅是指定的类型。任何帮助都会有帮助。

SELECT DISTINCT wp_posts.* 
FROM wp_posts, wp_term_relationships, wp_terms, wp_term_taxonomy 
WHERE 1=1 
AND wp_posts.ID = wp_term_relationships.object_id 
AND wp_terms.term_id = wp_term_taxonomy.term_id 
AND wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id 
AND wp_posts.post_type IN ('insight') 
AND wp_posts.post_status = 'publish' 
AND wp_posts.post_status != 'private' 
AND wp_posts.post_status != 'future' 
AND wp_posts.post_status != 'trash' 
AND wp_terms.slug LIKE '%great%' 
OR wp_posts.post_content LIKE '%great%' 
LIMIT 0, 10
mxg2im7a

mxg2im7a1#

你的问题可能出在你的问题上 OR ,您应该使用 OR 内圆括号 () . 当您这样做时,查询将忽略之前的所有子句。试试这个:

AND ( wp_terms.slug LIKE '%great%' OR wp_posts.post_content LIKE '%great%' )

相关问题