为动态字段生成meta_query的最佳方法是什么?我有一个动态数量的键,值可以是多个或单个。我当时正在考虑在循环中使用compare ='IN'进行循环,但不确定如何将数组推出来构建最终的meta_query,如下所示。
eg: http://www.website.com/events?city=melbourne,sydney&month=june,july&day=saturday
$meta_query = array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'city',
'value' => 'melbourne',
'compare' => '='
),
array(
'key' => 'city',
'value' => 'sydney',
'compare' => '='
)
),
array(
'relation' => 'OR',
array(
'key' => 'month',
'value' => 'june',
'compare' => '='
),
array(
'key' => 'month',
'value' => 'july',
'compare' => '='
)
),
array(
'key' => 'day',
'value' => 'saturday',
)
);