add_shortcode( 'job_search', 'job_search' ); function job_search($atts){ $taxonomy = "job_listing_type"; $terms = get_terms($taxonomy, array( "orderby" => "name", "hide_empty" => false ) ); $hierarchy = _get_term_hierarchy($taxonomy); ?> <form action="" method="get" class="activity_filter"> <div class="job-type-row"> <label for="search_location"><?php esc_html_e( 'Job Type', 'wp-job-manager' ); ?></label> <select name="job_listing_type" id="job_listing_type" class="job_listing_type"> <option value="">Select Job Type</option> <?php /** Loop through every term */ foreach($terms as $term) { /** Skip term if it has children */ if($term->parent) { continue; } $selected = ($term->slug==$_GET['job_listing_type']) ? "selected=true" : "" ; echo '<option '.$selected.' value="' . $term->slug . '">' . $term->name . '</option>'; /** If the term has children... */ if($hierarchy[$term->term_id]) { /** ...display them */ foreach($hierarchy[$term->term_id] as $child) { /** Get the term object by its ID */ $child = get_term($child, "category"); $selected = ($term->slug==$_GET['job_listing_type']) ? "selected=true" : "" ; echo '<option '.$selected.' value="' . $term->slug . '"> - ' . $child->name . '</option>'; } } } ?> </select> </div> <div class="search_location"> <label for="search_location"><?php esc_html_e( 'Location', 'wp-job-manager' ); ?></label> <input type="text" name="search_location" id="search_location" placeholder="<?php esc_attr_e( 'Location', 'wp-job-manager' ); ?>" value="<?php echo esc_attr( @$_GET['search_location'] ); ?>" /> </div> <div class="search_categories salary"> <label for="search_categories"><?php _e( 'Search Salary Amounts', 'wp-job-manager' ); ?></label> <select name="filter_by_salary" id="filter_by_salary"> <option value="0">Select Expected Salary</option> <option value="30,000 - 49,999">$30,000 - $49,999</option> <option value="50,000 - 69,999">$50,000 - $69,999</option> <option value="70,000 - 89,999">$70,000 - $89,999</option> <option value="90,000 - 109,999">$90,000 - $109,999</option> <option value="110,000 - 129,999">$110,000 - $129,999</option> <option value="130,000 - 149,999">$130,000 - $149,999</option> <option value="150,000+">$150,000 +</option> </select> </div> <div class="search_categories years"> <label for="search_categories"><?php _e( 'Years of experience', 'wp-job-manager' ); ?></label> <select name="filter_by_experience" id="filter_by_experience"> <option value="">Years of experience</option><option value="0">0</option><option value="1-2">1-2</option><option value="2-5">2-5</option><option value="5-10">5-10</option><option value="10+">10+</option> </select> </div> <div class="search_categories education"> <label for="education"><?php _e( 'Select Job Education', 'wp-job-manager' ); ?></label> <select name="education" id="education"> <option value="">Select Job Education</option> <option value="Less than High School">Less than High School</option> <option value="High School Diploma">High School Diploma</option> <option value="College">College</option> <option value="Associate’s Degree">Associate’s Degree</option> <option value="Bachelor’s Degree">Bachelor’s Degree</option> <option value="Professional or Doctorate">Professional or Doctorate</option> </select> </div> <p> <input type="submit" value="Search" /> <a href="<?php the_permalink();?>" class="reset">Reset</a> </p> </form> <?php $query_args = array( 'post_type' => 'job_listing', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', ); if($_GET['filter_by_experience']){ $query_args['meta_query'][] = array( 'key' => 'years_experience', 'value' => $_GET['filter_by_experience'], 'compare' => '=', ); } if($_GET['search_location']){ $query_args['meta_query'][] = array( 'key' => '_job_location', 'value' => $_GET['search_location'], 'compare' => 'LIKE', ); } if($_GET['filter_by_salary']){ $query_args['meta_query'][] = array( 'key' => '_job_salary', 'value' => $_GET['filter_by_salary'], 'compare' => 'LIKE', ); } if($_GET['education']){ $query_args['meta_query'][] = array( 'key' => '_education', 'value' => $_GET['education'], 'compare' => 'LIKE', ); } if($_GET['job_listing_type']){ $query_args['tax_query'][] = array( array( 'taxonomy' => 'job_listing_type', 'field' => 'slug', 'terms' => $_GET['job_listing_type'], ), ); } //$jobs = get_job_listings( $query_args ); $jobs = new WP_Query($query_args); echo ' <div class="job_listings">'; if ( $jobs->have_posts() ) { ?> <ul class="job_listings"> <?php while ( $jobs->have_posts() ) : $jobs->the_post(); ?> <?php //$country = get_post_meta(get_the_ID(), 'geolocation_country_short', true); ?> <?php get_job_manager_template_part( 'content-widget', 'job_listing' ); ?> <?php endwhile; ?> </ul> <?php wp_reset_postdata(); }else{ echo '<p class="no-job">No Jobs Found!</p>'; }?> </div> <script> jQuery('#filter_by_salary option[value="<?php echo $_GET['filter_by_salary'];?>"]').attr("selected", "selected"); jQuery('#education option[value="<?php echo $_GET['education'];?>"]').attr("selected", "selected"); jQuery('#filter_by_experience option[value="<?php echo $_GET['filter_by_experience'];?>"]').attr("selected", "selected"); </script> <?php }
Jagdish Sarma Asked question June 9, 2022