I want all four category id in $_GET variable to search for categories
我正在使用此代码进行下拉: -
$category = array(
'show_option_all' => 'Select Tour',
'orderby' => 'name',
'show_count' => 0,
'taxonomy' => 'tour_category',
);
$tour_category = wp_dropdown_categories($category);
$line = array(
'show_option_all' => 'Select cruise Line',
'orderby' => 'name',
'echo' => 1,
'taxonomy' => 'genre',
);
$cruise_line = wp_dropdown_categories($line);
$month = array(
'show_option_all' => 'Select Month',
'orderby' => 'name',
'echo' => 1,
'taxonomy' => 'date_month',
);
$date_month = wp_dropdown_categories($month);
$length = array(
'show_option_all' => 'Select Trip Length',
'orderby' => 'name',
'echo' => 1,
'taxonomy' => 'writer',
);
$trip_length = wp_dropdown_categories($length);
实际上我想根据这四个类别进行搜索。 我以前的代码是: -
$text_field_label = _x( 'Search Tour', 'placeholder', 'adventure-tours' );
printf(
'<div class="%s">%s' .
'<div class="form-block__item form-block__field-width-icon">' .
'<input type="text" %svalue="%s" name="s"><i class="td-search-1"></i>' .
'</div>' .
'</div>',
esc_attr( 'col-sm-' . $search_field_cells ),
$is_show_label ? sprintf( '<div class="form-block__item-label 1">%s</div>', esc_html( $text_field_label ) ) : '',
$is_show_label ? '' : sprintf( 'placeholder="%s" ', esc_attr( $text_field_label ) ),
get_search_query()
);
我在下拉列表中将其转换为四个不同的类别。
答案 0 :(得分:1)
尝试这样的事情
$query = explode('&', $_SERVER['QUERY_STRING']);
$param = array();
foreach( $query as $str)
{
list($name, $value) = explode('=', $str, 2);
$param[urldecode($name)][] = urldecode($value);
}
print_r($param);
答案 1 :(得分:0)
我在这里注意到的第一件事是你对所有四个选择框使用相同的名称。
因为如果你没有在name
函数的参数中添加wp_dropdown_categories
属性,那么它将自动使用默认名称,即cat
。
因此,为每个选择框添加不同的name
属性,以便在提交表单时,您将在GET
查询字符串中有四个不同的选择变量,如下所示:
$category = array(
'show_option_all' => 'Select Tour',
'orderby' => 'name',
'show_count' => 0,
'name' => 'cat-tour',
'taxonomy' => 'tour_category',
);
$tour_category = wp_dropdown_categories($category);
$line = array(
'show_option_all' => 'Select cruise Line',
'orderby' => 'name',
'echo' => 1,
'name' => 'cat-genre',
'taxonomy' => 'genre',
);
$cruise_line = wp_dropdown_categories($line);
$month = array(
'show_option_all' => 'Select Month',
'orderby' => 'name',
'echo' => 1,
'name' => 'cat-date',
'taxonomy' => 'date_month',
);
$date_month = wp_dropdown_categories($month);
$length = array(
'show_option_all' => 'Select Trip Length',
'orderby' => 'name',
'echo' => 1,
'name' => 'cat-writer',
'taxonomy' => 'writer',
);
$trip_length = wp_dropdown_categories($length);
希望它有所帮助。