2013-04-08 64 views
1

我在寫一個shorcode API函數。我想要保存wp_dropdown_categories中的選定值以使用wp_query中的值。WP下拉類別選定的值

echo `<form action="" method="POST">`; 
    $values = array(
    `orderby` => `name`, 
    `order` => `ASC`, 
    `echo` => 1, 
    `selected` => $kat = get_query_var(`cat`), 
    `name` => 'cat', 
    `id` => ``, 
    `taxonomy` => `persons` 
); 
    wp_dropdown_categories($values); 
echo `<input type="submit" name="submit" value="view" />; 
echo `</form>`; 

我想用所選值的自定義分類

$args = array(
    `post_type` => `client`, 
    `persons` => `here selected value from wp_dropdown_categories` 
); 
$my_query = new WP_Query($args); 

if($my_query->have_posts()) { 
    echo `Name: `; 
    while ($my_query->have_posts()) : $my_query->the_post(); 
    echo the_title(); 
    endwhile; 
} 
+0

什麼是這裏的問題???? – 2013-04-08 17:50:20

+0

想要從wp_dropdown_categories保存選定的值,並在'persons' =>'here selected value'中使用它。在我的例子中,我只能保存選定值的ID。 – user2202313 2013-04-08 18:03:06

回答

1

嘗試以下搜索...

<select name="category_list"> 
<option value="">Please Select</option> 
<?php 
    $values = array(
     `orderby` => `name`, 
     `order` => `ASC`, 
     `echo` => 1, 
     `selected` => $kat = get_query_var(`cat`), 
     `name` => 'cat', 
     `id` => ``, 
     `taxonomy` => `persons` 
    ); 
    $categories = get_categories($values); 
    foreach ($categories as $category) { 
    $option = '<option value="'.$category->name.'">'; 
    $option .= $category->cat_name; 
    $option .= '</option>'; 
    echo $option; 
    } 
?> 
</select> 

編號:http://codex.wordpress.org/Function_Reference/get_categories

+0

曾與此: 的$ args =陣列( \t 'post_type'=> '客戶', 'tax_query'=>數組( 陣列( '分類'=> '人', '術語'=>數組($ kat), 'field'=>'id', ) ) ); – user2202313 2013-04-09 09:45:09