自定义分类法查询" IN"或" NOT IN"

时间:2016-07-08 07:33:58

标签: mysql wordpress metadata

我正在尝试处理此查询

$query->set( 'tax_query', array(
                'relation' => 'OR',
                array(
                    'taxonomy' => 'location',
                     'operator' => 'IN',
                    'field' => 'slug',
                    'terms' => $availableRegions,
                ),
                array(
                    'taxonomy' => 'location',
                     'operator' => 'NOT IN',
                    'field' => 'slug',
                    'terms' => $notavailableRegions,
                )
            ));

此税务查询的SQL查询是:

SELECT wp_posts.ID
FROM wp_posts 
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id) JOIN wp_icl_translations t
ON wp_posts.ID = t.element_id 
AND t.element_type IN ('bla') JOIN wp_icl_languages l
ON t.language_code=l.code
AND l.active=1
WHERE 1=1  


AND (
wp_term_relationships.term_taxonomy_id IN (200) 

OR wp_posts.ID NOT IN ( 
SELECT object_id 
FROM wp_term_relationships 
WHERE term_taxonomy_id IN (201,203,205,206) )
)

但这不是我真正需要的

我希望查询如下:

SELECT wp_posts.ID
FROM wp_posts 
INNER JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id) JOIN wp_icl_translations t
ON wp_posts.ID = t.element_id 
AND t.element_type IN ('bla') JOIN wp_icl_languages l
ON t.language_code=l.code
AND l.active=1
WHERE 1=1  


AND (
wp_term_relationships.term_taxonomy_id IN (200) 


/* What I need to be is this line */
OR wp_term_relationships.term_taxonomy_id NOT IN (201,203,205,206)

)

或者如果我可以选择(" NOT_EXIST"或" IN")对我也有好处,任何保存我周末人的建议。

0 个答案:

没有答案