2

到目前为止,这是通过过滤并仅显示“会话”“秋季”项目来工作的。

<?php       
    $the_query = new WP_Query( array( 
            'post_type' => 'classes',
            'meta_key' => 'sessions'
            'meta_value' => 'Fall',
            'posts_per_page' => -1
            ));

    while ($the_query->have_posts()) :
    $the_query->the_post(); 
?>

但我希望它也过滤并仅显示“秋季”和“Monon 社区中心”中的项目

'meta_key' => 'location_select',
'meta_value' => 'Monon Community Center',

我怎样才能做到这一点?

我也试过这个,它没有用

                        $the_query = new WP_Query( array( 
            'post_type' => 'classes',
            'meta_query' => array(
                        'relation' => 'AND',
                        array(
                                'meta_key' => 'location_select',
                                'meta_value' => 'Monon Community Center',
                                'compare' => '='),
                        array(
                                'meta_key' => 'sessions',
                                'meta_value' => 'fall',
                                'compare' => '='),
                        'posts_per_page' => -1
                )
                ));
        while ($the_query->have_posts()) :
        $the_query->the_post(); 
4

1 回答 1

0

http://codex.wordpress.org/Class_Reference/WP_Query上的“自定义字段参数”下,您可以传递一个元查询,它是一个数组:

$meta_query = array(
    array("key" => "value", "value" => "value2", "compare" => ""),
    array("key" => "value3", "value" => "value4", "compare" => "")
);`
于 2013-05-20T20:45:20.177 回答