我的问题是关于php的,但是在我创建插件时涉及到wordpress。情况是我有5个问题,每个问题有6个选择,每个选择一个。现在,此人可以从每个选择中选择一个,也可以选择几个。我已经创建了if条件,现在该条件使我发疯,因为它已经太久了,并且会进一步发展,就像将进行近100种组合一样。我不希望那样,我知道有一种多维数组的方法,但是不是wordpress的插件或PHP专家。因此,如果有人可以为我排序。
$qs = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
$q4 = $_POST['q4'];
$q5 = $_POST['q5'];
$q6 = $_POST['q6'];
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'fashion-follower'
),
// array(
// 'taxonomy' => 'product_cat',
// 'field' => 'slug',
// 'terms' => 'cheap-and-cheerful'
// )
)
);
//The Fashionsia
if (($qs ==='party') && ($q2 === 'clothes') && ($q3 === 'shopping') && ($q5 === 'Sunbathing') && ($q6 === 'mini')){
$query = new WP_Query( $args );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();
the_post_thumbnail('thumbnail');
endwhile;
endif;
}
//second question loop
$args2 = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'the-homemaker'
),
// array(
// 'taxonomy' => 'product_cat',
// 'field' => 'slug',
// 'terms' => 'cheap-and-cheerful'
// )
)
);
//The homemaker
if (($qs ==='drink') && ($q2 === 'candles') && ($q3 === 'house') && ($q4 === 'diy')){
$query = new WP_Query( $args2 );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();
the_post_thumbnail('thumbnail');
endwhile;
endif;
}
//third loop
$args3 = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'entertainment'
),
// array(
// 'taxonomy' => 'product_cat',
// 'field' => 'slug',
// 'terms' => 'cheap-and-cheerful'
// )
)
);
//The Entertainer
if (($qs ==='party-babe') && ($q2 === 'winer')&& ($q4 === 'storm') && ($q6 === 'limo')){
$query = new WP_Query( $args3 );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();
the_post_thumbnail('thumbnail');
endwhile;
endif;
}
//fourth loop
$args4 = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'family-fanatic'
),
// array(
// 'taxonomy' => 'product_cat',
// 'field' => 'slug',
// 'terms' => 'cheap-and-cheerful'
// )
)
);
//The family-fanatic
if (($qs ==='movie') && ($q2 === 'kids')&& ($q6 === 'volvo')){
$query = new WP_Query( $args4 );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();
the_post_thumbnail('thumbnail');
endwhile;
endif;
}
//fifth loop
//fourth loop
$args4 = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'family-fanatic'
),
// array(
// 'taxonomy' => 'product_cat',
// 'field' => 'slug',
// 'terms' => 'cheap-and-cheerful'
// )
)
);
//The romantic
if (($qs ==='Dinner-show') && ($q5 === 'cruiser')){
$query = new WP_Query( $args4 );
if( $query->have_posts()) : while( $query->have_posts() ) : $query->the_post();
the_post_thumbnail('thumbnail');
endwhile;
endif;
}