【发布时间】:2018-10-05 11:42:45
【问题描述】:
我有三个数组 ($genneral , $step_1 , $step_2),我已经将它们组合成特定的格式
if (ISSET($_GET['step_1'])){
$step_1 = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $_GET['step_1']
);
}
if(ISSET($_GET['step_2'])){
$all_data=explode(",",$_GET['step_2']);
for ($i=0; $i<count($all_data); $i++){
$step_2[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' =>$all_data[$i]
);
}
}
$genneral = array(
'post_status' => 'publish',
'post_type' => 'product',
'orderby' => 'title',
'posts_per_page' => -1
);
所以我必须从这三个数组中以特定格式组合这三个数组
if $_GET['step_1']=red
if $_GET['step_2']=hard,soft
那么结果参数应该是这样的,
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'post_type' => 'product',
'orderby' => 'title',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'red' ),
),
array(
'relation' => 'OR',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'hard' ),
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'soft' ),
),
),
)
);
请帮助解决这个问题。我知道这很难,但有人可以给出答案,这将非常有帮助。
请注意有时
$_GET['step_2']包含许多字符串,例如$_GET['step_2']=hard,soft,boiled, melt..
【问题讨论】:
标签: php arrays wordpress multidimensional-array