简体   繁体   English

WordPress搜索查询不起作用

[英]Wordpress Search Query Not Working

I'm trying to figure out why this query returns all post types and not just the ones specified. 我试图弄清楚为什么此查询返回所有帖子类型,而不仅仅是返回指定的类型。 Any help would be helpful. 任何帮助都会有所帮助。

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

Your problem probably it's in your OR , you should use the OR inside parentheses () . 您的问题可能出在您的OR ,您应该在括号()使用OR As you are doing, the query will ignore all your clauses before. 在执行操作时,查询将忽略之前的所有子句。 Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM