多元meta_key和meta_value

时间:2017-02-06 06:38:46

标签: wordpress

$args = array(
    'post_type' => array('project','department'),
    'meta_query' => array(
        array(
            'key' => 'jurisdiction',
            'value' => $where,
            'compare' => '='
        ),
        array(
            'key' => 'title',
            'value' => $cat,
            'compare' => '='
        ),
        array(
            'key' => 'status',
            'value' => $type,
            'compare' => '='
        )
    )
);

$loop = new WP_Query($args);

while ($loop->have_posts()) : $loop->the_post();
    global $post;
    the_title();
endwhile;

会产生以下错误

  

警告:trim()要求参数1为字符串,在第584行的/var/www/.../wp-includes/class-wp-meta-query.php中给出数组

1 个答案:

答案 0 :(得分:0)

首先:在meta_query中,不要接受数组变量。 只检查这个($ where,$ cat和$ type)变量给你正确的值?

第二:可能是你忘了在meta_query中写关系属性。

 $args = array(
    'post_type' => array('project','department'),
    'meta_query' => array(
        'relation' => 'OR', // Optional, defaults to "AND"
        array(
            'key' => 'jurisdiction',
            'value' => $where,
            'compare' => '='
        ),
        array(
            'key' => 'title',
            'value' => $cat,
            'compare' => '='
        ),
        array(
            'key' => 'status',
            'value' => $type,
            'compare' => '='
        )
    )
);

我希望它对你有帮助