get_users meta_query

时间:2013-01-14 作者:jamessy

我无法使meta\\u查询在get\\u users()上正常工作。我一辈子都不知道自己做错了什么。

    $args = array(
        \'meta_query\'   =>

            array(
                \'relation\' => \'AND\',

            array(
                \'key\' => \'minbeds\',
                \'value\' => $rooms,
                \'compare\' => "<=",
                \'type\' => \'numeric\'
            ),
            array(
                \'key\' => \'maxbeds\',
                \'value\' =>  $rooms,
                \'compare\' => "=>",
                \'type\' => \'numeric\'
            )
           array(
                \'key\' => \'minprice\',
                \'value\' => $price,
                \'compare\' => "<=",
                \'type\' => \'numeric\'
            ),
            array(
                \'key\' => \'maxprice\',
                \'value\' => $price,
                \'compare\' => "=>",
                \'type\' => \'numeric\'
            )
         )
    );

    $users = get_users( $args );

1 个回复
最合适的回答,由SO网友:anu 整理而成

meta_query 参数是数组的数组,

    $args = array(
        \'meta_query\'=>

         array(

            array(

                \'relation\' => \'AND\',

            array(
                \'key\' => \'minbeds\',
                \'value\' => $rooms,
                \'compare\' => "<=",
                \'type\' => \'numeric\'
            ),

            array(
                \'key\' => \'maxbeds\',
                \'value\' =>  $rooms,
                \'compare\' => ">=",
                \'type\' => \'numeric\'
            ),

           array(
                \'key\' => \'minprice\',
                \'value\' => $price,
                \'compare\' => "<=",
                \'type\' => \'numeric\'
            ),

            array(
                \'key\' => \'maxprice\',
                \'value\' => $price,
                \'compare\' => ">=",
                \'type\' => \'numeric\'
            )
          )
       )
    );

    $users = get_users( $args );

结束