Help on multiple meta_query

时间:2013-10-21 作者:jam

我试图从WP数据库中获取带有两个meta\\u键值的帖子,但结果是0 职位。

打印参数:

Array ( 
    [taxonomy] => cardstax 
    [term] => christmas 
    [post_type] => cards 
    [paged] => 1 
    [caller_get_posts] => 1 
    [meta_query] => Array ( 
        [relation] => AND 
        [0] => Array (
            [key] => card_format[value] => Little card 
        )
        [1] => Array ( 
            [key] => price_lvl 
            [value] => Array ( 
                [0] => 0.06 
                [1] => 0.97 
                ) 
            [type] => NUMERIC 
            [compare] => BETWEEN 
            ) 
        ) 
    )
元查询本身

\'taxonomy\' => $term->taxonomy,
\'term\' => $term->slug,
\'post_type\' => \'cards\',
\'paged\'=> $paged,
\'caller_get_posts\'=> 1,    
\'meta_query\' => array(
    \'relation\' => \'AND\',
    array(
        \'key\'     => \'card_format\',
        \'value\'   => \'Little card\'
    ),
    array(
        \'key\'     => \'price_lvl\',
        \'value\'   => array( "0.06","0.97" ),
        \'type\'    => \'NUMERIC\',
        \'compare\' => \'BETWEEN\'
        )
    ),
SQL语法:

SELECT SQL_CALC_FOUND_ROWS plt_posts.ID
FROM plt_posts
INNER JOIN plt_term_relationships ON ( plt_posts.ID = plt_term_relationships.object_id ) 
INNER JOIN plt_postmeta ON ( plt_posts.ID = plt_postmeta.post_id ) 
INNER JOIN plt_postmeta AS mt1 ON ( plt_posts.ID = mt1.post_id ) 
JOIN plt_icl_translations t ON plt_posts.ID = t.element_id
    AND t.element_type =  \'post_cards\'
JOIN plt_icl_languages l ON t.language_code = l.code
    AND l.active =1
WHERE 1 =1
    AND ( plt_term_relationships.term_taxonomy_id IN ( 27 ) )
    AND plt_posts.post_type =  \'cards\'
    AND (
        plt_posts.post_status =  \'publish\'
        OR plt_posts.post_status =  \'private\'
    )
    AND (
        (
        plt_postmeta.meta_key =  \'card_format\'
        AND CAST( plt_postmeta.meta_value AS CHAR ) =  \'Little card\'
    )
    AND (
        mt1.meta_key =  \'price_lvl\'
        AND CAST( mt1.meta_value AS SIGNED ) 
            BETWEEN  \'0.06\'
            AND  \'0.97\'
        )
    )
    AND t.language_code =  \'lv\'
GROUP BY plt_posts.ID
ORDER BY plt_posts.post_date DESC 
LIMIT 0 , 12
没有那部分

AND (
    mt1.meta_key =  \'price_lvl\'
    AND CAST( mt1.meta_value AS SIGNED ) 
        BETWEEN  \'0.06\'
        AND  \'0.97\'
    )
查询工作正常,我得到了一个帖子ID列表。

2 个回复
SO网友:Otto

删除第二个元查询的值周围的引号。你把数字和字符进行比较,这是行不通的。

SO网友:jam

将十进制和数字改为CHAR,结果成功了。

结束

相关推荐