1

我正在编写一个 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;
}
4

1 回答 1

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

于 2013-04-09T02:29:13.403 回答