2017-05-04 54 views
0

By selecting search item and click on find tour i want to search particular categories but in print_r($_GET) i received on only one category id如何在WordPress中獲取所有的URL變量數據?

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

在您的URL中使用cat1,cat2,cat3和cat4 –

回答

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); 
+0

如何在wordpress中添加此項? –

+0

如何調用print_r($ _GET) –

+0

我想在WordPress中獲得這些全部參數。 –

0

,我注意到這裏的第一件事是,你是爲所有四個選擇框使用相同的名稱。

因爲如果您不在wp_dropdown_categories函數的參數中添加name屬性,則它會自動使用默認名稱,即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); 

希望它能幫助。