Custom job search form with Category not working properly
-
Hi, I followed this tutorial – https://wpjobmanager.com/document/tutorial-creating-custom-job-search-form/
Though, i’ve created a shortcode for it. See the function below, search_categories not working at all. Please visit the link (Link to the page you need help with:), you can test the form.
function ed_job_search_form($atts, $content = null) { global $wpdb; $atts = shortcode_atts( array( 'id' => '', 'class' => '', ), $atts ); $job_locations = $wpdb->get_results("SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = '_job_location' and pm.post_id=p.ID and p.post_type='job_listing' ORDER BY pm.meta_value ",ARRAY_A); $html = ''; $search_keywords = isset($_GET['search_keywords']) ? $_GET['search_keywords'] : ''; $search_location = isset($_GET['search_location']) ? $_GET['search_location'] : ''; $search_categories = isset($_GET['search_categories']) ? $_GET['search_categories'] : ''; $html .= '<form method="GET" action="' . job_manager_get_permalink('jobs') . '" class="job-search-form">'; $html .= '<div class="row">'; $html .= '<div class="col-xl-3">'; $html .= '<input type="text" id="search_keywords" name="search_keywords" class="form-control" placeholder="Keywords" value="' . $search_keywords . '" />'; $html .= '</div>'; $html .= '<div class="col-xl-3">'; $html .= '<select id="search_location" name="search_location" class="form-control">'; $html .= '<option value="">Location</option>'; foreach ( $job_locations as $job_location ) { $html .= '<option value="' . esc_attr( $job_location['meta_value'] ) . '" ' . ($search_location == $job_location['meta_value'] ? 'selected' : '') . '>' .esc_html( $job_location['meta_value'] ) .'</option>'; } $html .= '</select>'; $html .= '</div>'; $html .= '<div class="col-xl-3">'; $html .= '<select name="search_categories" id="search_categories" class="form-control">'; $html .= '<option value="">Category</option>'; foreach ( get_job_listing_categories() as $cat ) { $html .= '<option value="' . esc_attr( $cat->term_id ) . '" ' . ($search_categories == $cat->term_id ? 'selected' : '') . '>' .esc_html( $cat->name ) .'</option>'; } $html .= '</select>'; $html .= '</div>'; $html .= '<div class="col-xl-3">'; $html .= '<button type="submit" class="btn btn-hexagon">'; $html .= '<span class="btn-hexagon-label">Search <i class="fas fa-search"></i></span>'; $html .= '</button>'; $html .= '</div>'; $html .= '</div>'; $html .= '</form>'; return $html; } add_shortcode( 'ed-job-search-form', 'ed_job_search_form' );
Thank you
The page I need help with: [log in to see the link]
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Custom job search form with Category not working properly’ is closed to new replies.