使用构造的数组,我认为这是正确的语法:
$meta_query_args = array(
\'meta_key\' => \'price\',
\'meta_value_num\' => 1000,
\'meta_compare\' => \'<=\',
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'roomcount\',
\'value\' => 3,
\'type\' => \'numeric\',
\'compare\' => \'>=\'
),
array(
\'key\' => \'bathroomcount\',
\'value\' => 2,
\'type\' => \'numeric\',
\'compare\' => \'>=\'
)
)
);
$realestate_meta_query = new WP_Query( $meta_query_args );
您也可以尝试嵌套
meta_query
还有一个级别(虽然我不知道这是否有效):
$meta_query_args = array(
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'price\',
\'value\' => 1000,
\'type\' => \'numeric\',
\'compare\' => \'<=\'
),
array(
\'relation\' => \'OR\',
array(
\'key\' => \'roomcount\',
\'value\' => 3,
\'type\' => \'numeric\',
\'compare\' => \'>=\'
),
array(
\'key\' => \'bathroomcount\',
\'value\' => 2,
\'type\' => \'numeric\',
\'compare\' => \'>=\'
)
)
)
);
$realestate_meta_query = new WP_Query( $meta_query_args );