-1

meta_query在 Wordpress 中遇到问题。第一个例子工作正常:

$args = array(
    'post_type' => 'my_post',
    'meta_query' => 
    array(
        array(
            'key' => 'my_field', 
            'value' => '50', 
            'compare' => 'LIKE',
        ),
    ),    
);

$query = new WP_Query( $args );

但是我想要做的,如下所示,在 Wordpress 文档中,不起作用。

$args = array(
    'post_type' => 'my_post',
    'meta_query' => 
    array(
        array(
            'key' => 'my_field', 
            'value' => array('50','60'), 
            'compare' => 'IN',
        ),
    ),    
);

$query = new WP_Query( $args );
4

1 回答 1

0
$args = array(
    'post_type' => 'my_post',
    'meta_query' => 
    array(
        array(
            'key' => 'my_field', 
            'value' => array(50,60), 
            'type' => 'numeric',
            'compare' => 'IN'
        ),
    ),    
);

$query = new WP_Query( $args );

我假设它array('50','60')是数字的。尝试删除撇号并添加正确类型的数字。

于 2013-04-15T02:10:43.657 回答