使用SQL在wordpress中搜索多个术语

时间:2012-08-10 19:17:24

标签: sql wordpress tags

我正在尝试编写一个sql查询,如果它们匹配给定的整个术语集,它们将返回帖子:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
FROM wp_posts 

LEFT JOIN wp_term_relationships AS trel ON (wp_posts.ID = trel.object_id) 
LEFT JOIN wp_term_taxonomy AS ttax ON (ttax.taxonomy = 'business-tags' AND trel.term_taxonomy_id = ttax.term_taxonomy_id) 
LEFT JOIN wp_terms AS tter ON (ttax.term_id = tter.term_id)

WHERE 1=1 
AND (tter.slug LIKE '%crazy%' AND tter.slug LIKE '%insane%')  
AND wp_posts.post_type = 'business' 
AND wp_posts.post_status = 'publish'

我在数据库中有一个包含这两个标记的帖子。现在,如果我只搜索一个标签,我会得到结果,但是当我做多个标签时,它会返回零结果。关于我可能做错的任何建议?

0 个答案:

没有答案