WordPressのキーワード・タクソノミー(セレクト・チェックボックス)の複合検索
WordPressのキーワード・タクソノミー(セレクト・チェックボックス)の複合検索メモ
<form method="get" action="<?php echo esc_url(home_url('/'));?>" name="worksearch"> <input type="text" name="s" id="s" value="<?php echo get_search_query(); ?>" placeholder="キーワード"> <?php //カスタム投稿タイプの一覧を取得 $args = array( 'public' => true, '_builtin' => false ); $post_types = get_post_types( $args ); ?> <!-- <?php if(count($post_types) != 0):?> <select name="post_type"> <?php foreach ( $post_types as $post_type ) : ?> <option value="<?php echo $post_type; ?>"><?php echo esc_html( get_post_type_object( $post_type )->label ); ?></option> <?php endforeach;?> </select> <?php endif; ?> --> <select name="post_type" style="display: none;"> <option value="work" selected>求人情報</option> </select> <?php $selected = get_query_var("work_area",0); $args = array( 'show_option_all' => '勤務地を選ぶ', 'taxonomy' => 'work_area', 'name' => 'work_area', 'value_field' => 'slug', 'hide_empty' => false, 'hierarchical'=> true, 'selected' => $selected ); wp_dropdown_categories($args); ?> <?php $selected = get_query_var("work_occupation",0); $args = array( 'show_option_all' => '職種を選ぶ', 'taxonomy' => 'work_occupation', 'name' => 'work_occupation', 'value_field' => 'slug', 'hide_empty' => false, 'selected' => $selected ); wp_dropdown_categories($args); ?> <?php $selected = get_query_var("work_status",0); $args = array( 'show_option_all' => '雇用形態を選ぶ', 'taxonomy' => 'work_status', 'name' => 'work_status', 'value_field' => 'slug', 'hide_empty' => false, 'selected' => $selected ); wp_dropdown_categories($args); ?> <?php /* $selected = get_query_var("work_commitment",0); $args = array( 'descendants_and_self' => 0, 'selected_cats' => false, 'popular_cats' => false, 'walker' => null, 'taxonomy' => 'work_commitment', 'checked_ontop' => true ); wp_terms_checklist($args); */ ?> <ul> <?php $terms = get_terms('work_commitment','hide_empty=0'); foreach ( $terms as $term ) : ?> <li> <label> <input type="checkbox" name="work_commitment" value="<?php echo $term->slug; ?>" id="<?php echo $term->term_id;; ?>"><?php echo $term->name; ?> </label> </li> <?php endforeach; ?> </ul> <input type="submit" value="検索"> </form>