WordPress使用LIKE查询数组

时间:2017-02-15 17:14:52

标签: wordpress

我有一个如下所示的查询:

$data = get_posts( array(
        'post_type'   => 'custom_type',
        'post_status' =>  'any',
        'posts_per_page' => 200,
        'order'     => 'ASC',
        'meta_key' =>'_customer_start',
        'orderby' => 'meta_value',
        'meta_query' => array(
        array(
         'key'     => '_customer_id',
         'value'   => $customer_id,
         'compare' => 'IN'
            ),
        array(
         'key'     => '_customer_start',
         'value'   => $_customer_start,
         'compare' => 'LIKE'
                )
            )
        )
    );

此查询的输入是两个数组:

$customer_id = array(2808,2814);
$_customer_start = array('20170212','20170224');

我的问题是,这会产生以下错误:

Warning: trim() expects parameter 1 to be string, array given in ..../wp-includes/class-wp-meta-query.php on line 597

我遇到了麻烦,看起来问题是第二个数组,传递一组日期进行LIKE比较。我不能使用IN比较(因为建议用于数组),因为存储的日期包括时间。因此,如果我使用IN或EQUALS,我将找不到它们。

是否有一种传递数组进行LIKE比较的方法,而不是动态扩展查询?

0 个答案:

没有答案
相关问题