/** * Based on wp_dropdown_categories, with the exception of supporting multiple selected categories. * @see wp_dropdown_categories */ function job_manager_dropdown_categories($args = '') { $defaults = array('orderby' => 'id', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'job-manager-category-dropdown ' . (is_rtl() ? 'chosen-rtl' : ''), 'depth' => 0, 'taxonomy' => 'job_listing_category', 'value' => 'id', 'placeholder' => __('Choose a category…', 'wp-job-manager')); $r = wp_parse_args($args, $defaults); if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { $r['pad_counts'] = true; } extract($r); $categories = get_terms($taxonomy, $r); $name = esc_attr($name); $class = esc_attr($class); $id = $id ? esc_attr($id) : $name; $output = "<select name='{$name}[]' id='{$id}' class='{$class}' multiple='multiple' data-placeholder='{$placeholder}'>\n"; if (!empty($categories)) { include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-category-walker.php'; $walker = new WP_Job_Manager_Category_Walker(); if ($hierarchical) { $depth = $r['depth']; // Walk the full depth. } else { $depth = -1; // Flat. } $output .= $walker->walk($categories, $depth, $r); } $output .= "</select>\n"; if ($echo) { echo $output; } return $output; }
/** * Based on wp_dropdown_categories, with the exception of supporting multiple selected categories. * @see wp_dropdown_categories */ function job_manager_dropdown_categories($args = '') { $defaults = array('orderby' => 'id', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'job-manager-category-dropdown ' . (is_rtl() ? 'chosen-rtl' : ''), 'depth' => 0, 'taxonomy' => 'job_listing_category', 'value' => 'id', 'multiple' => true, 'show_option_all' => false, 'placeholder' => __('Choose a category…', 'wp-job-manager'), 'no_results_text' => __('No results match', 'wp-job-manager'), 'multiple_text' => __('Select Some Options', 'wp-job-manager')); $r = wp_parse_args($args, $defaults); if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { $r['pad_counts'] = true; } extract($r); // Store in a transient to help sites with many cats $categories_hash = 'jm_cats_' . md5(json_encode($r) . WP_Job_Manager_Cache_Helper::get_transient_version('jm_get_' . $r['taxonomy'])); $categories = get_transient($categories_hash); if (empty($categories)) { $categories = get_terms($taxonomy, array('orderby' => $r['orderby'], 'order' => $r['order'], 'hide_empty' => $r['hide_empty'], 'child_of' => $r['child_of'], 'exclude' => $r['exclude'], 'hierarchical' => $r['hierarchical'])); set_transient($categories_hash, $categories, DAY_IN_SECONDS * 30); } $name = esc_attr($name); $class = esc_attr($class); $id = $id ? esc_attr($id) : $name; $output = "<select name='" . esc_attr($name) . "[]' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "' " . ($multiple ? "multiple='multiple'" : '') . " data-placeholder='" . esc_attr($placeholder) . "' data-no_results_text='" . esc_attr($no_results_text) . "' data-multiple_text='" . esc_attr($multiple_text) . "'>\n"; if ($show_option_all) { $output .= '<option value="">' . esc_html($show_option_all) . '</option>'; } if (!empty($categories)) { include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-category-walker.php'; $walker = new WP_Job_Manager_Category_Walker(); if ($hierarchical) { $depth = $r['depth']; // Walk the full depth. } else { $depth = -1; // Flat. } $output .= $walker->walk($categories, $depth, $r); } $output .= "</select>\n"; if ($echo) { echo $output; } return $output; }
/** * Show category dropdown */ public function jobs_by_category() { global $typenow, $wp_query; if ($typenow != 'job_listing' || !taxonomy_exists('job_listing_category')) { return; } include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-category-walker.php'; $r = array(); $r['pad_counts'] = 1; $r['hierarchical'] = 1; $r['hide_empty'] = 0; $r['show_count'] = 1; $r['selected'] = isset($wp_query->query['job_listing_category']) ? $wp_query->query['job_listing_category'] : ''; $r['menu_order'] = false; $terms = get_terms('job_listing_category', $r); $walker = new WP_Job_Manager_Category_Walker(); if (!$terms) { return; } $output = "<select name='job_listing_category' id='dropdown_job_listing_category'>"; $output .= '<option value="" ' . selected(isset($_GET['job_listing_category']) ? $_GET['job_listing_category'] : '', '', false) . '>' . __('Select category', 'wp-job-manager') . '</option>'; $output .= $walker->walk($terms, 0, $r); $output .= "</select>"; echo $output; }