我正在编写shorcode API函数。我想保存wp_dropdown_categories
中的所选值,以便在wp_query
中使用该值。
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 :(得分: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