我的问题是关于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;
}