Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress查询参数如果有两个值,则_Php_Wordpress_Arguments - Fatal编程技术网

Php WordPress查询参数如果有两个值,则

Php WordPress查询参数如果有两个值,则,php,wordpress,arguments,Php,Wordpress,Arguments,也许这是一个非常愚蠢的问题,但我无法理解。当我阅读代码时,它是有意义的,它做了它所做的,但我不知道如何更改它以正常工作。以下是查询: return array( 'post_type' => 'page', 'post_status' => 'publish', 'meta_query' => array( 'is_featured' => array( 'key' =

也许这是一个非常愚蠢的问题,但我无法理解。当我阅读代码时,它是有意义的,它做了它所做的,但我不知道如何更改它以正常工作。以下是查询:

return array(
        'post_type' => 'page',
        'post_status' => 'publish',
        'meta_query' => array(
            'is_featured' => array(
                'key' => 'featured',
                'compare' => 'EXISTS'
            ),
            array(
                'key'       => 'pakket-of-dienst',
                'value'     => array('vps hosting'),
                'compare'   => 'IN',
            ),
        ),
        'orderby' => array(
            'is_featured' => 'DESC'
        )
    );
它会选择所有pakket的dienst值为“vps hosting”的页面,当存在键为“featured”的页面时,它也会显示此页面

问题是存在多个dienst值的包

我如何才能进行查询,仅选择dienst的pakket为“vps主机”且featured值为0或1的页面

现在的问题是,当dienst的pakket是“vps主机”时,他也会显示dienst的pakket的特色页面是“webhosting”

有人吗?

你能试试这个吗:

return [
    'post_type'   => 'page',
    'post_status' => 'publish',
    'meta_query'  => [
        'relation' => 'AND',
        [
            'relation' => 'OR',
            [
                'key'   => 'featured',
                'value' => 1
            ],
            [
                'key'   => 'featured',
                'value' => 0
            ]
        ],
        [
            'key'   => 'pakket-of-dienst',
            'value' => 'vps hosting', //no need "in" as you check against one value only
        ],
    ],
    'orderby'     => [
        'is_featured' => 'DESC'
    ]
];
注意:我倾向于避免使用“EXIST”操作符(对于meta_查询或tax_查询),而更喜欢在id或key/value上使用“IN”。我有时使用它会产生“意想不到的”结果