我的页面上有一个过滤器/搜索功能,最多包含 4 个下拉列表,下拉列表显示取决于最后一个下拉列表是什么...
在我的下拉列表中,我有 4 个潜在场景
车辆类型
<select name="vehicleType" id="vehicleType">
<option value="choose" selected="selected">Please choose</option>
<option value="hgv">HGV</option>
<option value="psv">PSV</option>
<option value="lgv">LGV</option>
// MORE OPTIONS AVAILABLE
</select>
覆盖区域
<select name="coverageRegion" id="coverageRegion">
<option value="choose" selected="selected">Please choose</option>
<option value="national">National</option>
<option value="international">International</option>
</select>
首选网站类型
<select name="locationType" id="locationType">
<option value="choose" selected="selected">Please choose</option>
<option value="truckstops">Truck stops at lowest price</option>
<option value="motorway">Branded motorway sites</option>
</select>
对于我的搜索功能,我目前使用“IF”语句,如果“vehicleType = X 和 Coverage Region = X”显示这些结果。
但是,我现在需要为县添加第四个下拉列表。在我的县部分中,将有大约 50 个县,我实际上无法为每种可能的情况提供 IF 声明,因为这将花费很长时间,最好的方法是什么?
我目前用我的 PHP 做的一个例子是......
if ($_POST['vehicleType'] == 'car' && $_POST['pricing'] == 'pump' ) {
$customkey = 'vehicleType';
$customvalue = 'car';
$customkey1 = 'pricing';
$customvalue1 = 'pump';
$args = array('orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'ASC',
'meta_query' => array(
array(
'key' => $customkey,
'value' => $customvalue,
'compare' => '='
),
array(
'key' => $customkey1,
'value' => $customvalue1,
'compare' => '='
)
)
);
$query = new WP_Query( $args );// The Loop
$i = 0; $i = -1;
while ( $query->have_posts() )
{
$i++;
$query->the_post();
if ( $keys = get_post_custom_keys() )
{
echo "<div class='clearfix card-prod ".($i==0?'first':'')."'><div class='top-dets'><span class='card-title'>";
echo the_title();
echo "</span>";
// Network query
$network_value = get_post_custom_values('srchnetwork');
foreach ( $network_value as $key => $value ) {
echo '<span class="srch-val-">'. $value . '</span>'; }// Pricing Query
$pricing_value = get_post_custom_values('srchpricing');
foreach ( $pricing_value as $key => $value ) {
echo '<span class="srch-val-1">'. $value . '</span>'; }
// Setup Query
$setup_value = get_post_custom_values('srchsetupfee');
foreach ( $setup_value as $key => $value ) {
echo '<span class="srch-val-2">'. $value . '</span>'; }
// Services Query
$services_value = get_post_custom_values('srchservices');
foreach ( $services_value as $key => $value ) {
echo '<span class="srch-val-3">'. $value . '</span></div>'; }
// Big Card Query
$bigcard_value = get_post_custom_values('bigcard');
foreach ( $bigcard_value as $key => $value ) {
echo '<a href="/" class="cardclick"><img src="/wp-content/themes/CAFC/images/cards/'. $value . '" alt="'; }
echo the_title() . '" /></a>';
echo '<img src="wp-content/themes/CAFC/images/top-choice.jpg" alt="Top Choice" class="topchoice">';
echo the_excerpt()."</div>";
}
}