Products
GG网络技术分享 2025-03-18 16:12 11
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
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我试图弄清楚为什么这个查询会返回所有帖子类型,而不仅仅是指定的帖子类型。 任何帮助都会有所帮助。</ p>
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 <n </ code> < / pre>
</ div>
网友观点:
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%\' )
Demand feedback