douyuai8994 2018-08-09 17:40
浏览 50
已采纳

Wordpress搜索查询不起作用

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
  • 写回答

1条回答 默认 最新

  • doujuanxun7167 2018-08-09 17:58
    关注

    Your problem probably it's in your OR, you should use the OR inside parentheses (). 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%' )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?