Altering search Criteria
-
I’m using the Jobify theme, w/ WP job manager plugin. I’m attempting to modify / add search criteria to the job search widget. I was able to add a drop down, that passes in correct information and outputs the correct queried arguments but its not actually doing any filtering. I could be misinterpreting the example provided by WP Job Manager, and hooking it in incorrectly. Any advice would be much appreciated.
Thanks in advance!
WPJM example: https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/#section-4
myGist: https://gist.github.com/cmehrabian/a5d1085061b1e0d17c48add_action( 'job_manager_job_filters_search_jobs_end', 'filter_by_school_field' ); function filter_by_school_field() { ?> <div class="search_categories"> <label for="search_categories"><?php _e( 'Salary', 'wp-job-manager' ); ?></label> <select name="filter_by_school" class="job-manager-filter"> <option value=""><?php _e( 'Any School', 'wp-job-manager' ); ?></option> <option value="cabrillo"><?php _e( 'Cabrillo', 'wp-job-manager' ); ?></option> <option value="csumb"><?php _e( 'CSUMB', 'wp-job-manager' ); ?></option> <option value="hartnell"><?php _e( 'Hartnell', 'wp-job-manager' ); ?></option> <option value="miis"><?php _e( 'MIIS', 'wp-job-manager' ); ?></option> <option value="mpc"><?php _e( 'MPC', 'wp-job-manager' ); ?></option> <option value="ucsc"><?php _e( 'UCSC', 'wp-job-manager' ); ?></option> </select> </div> <?php } /** * This code gets your posted field and modifies the job search query */ add_filter( 'job_manager_get_listings', 'filter_by_school_field_query_args', 10, 2 ); function filter_by_school_field_query_args( $query_args, $args ) { if ( isset( $_POST['form_data'] ) ) { parse_str( $_POST['form_data'], $form_data ); if ( ! empty( $form_data['filter_by_school'] ) ) { $selected_range = sanitize_text_field( $form_data['filter_by_school'] ); switch ( $selected_range ) { case 'cabrillo' : $query_args['meta_query'][] = array( 'key' => '_affiliated_school', 'value' => 'cabrillo', 'compare' => '=' ); break; case 'csumb' : $query_args['meta_query'][] = array( 'key' => '_affiliated_school', 'value' => 'csumb', 'compare' => '=' ); break; case 'hartnell' : $query_args['meta_query'][] = array( 'key' => '_affiliated_school', 'value' => 'hartnell', 'compare' => '=' ); break; case 'miis' : $query_args['meta_query'][] = array( 'key' => '_affiliated_school', 'value' => 'miis', 'compare' => '=' ); break; case 'mpc' : $query_args['meta_query'][] = array( 'key' => '_affiliated_school', 'value' => 'mpc', 'compare' => '=' ); break; case 'ucsc' : $query_args['meta_query'][] = array( 'key' => '_affiliated_school', 'value' => 'ucsc', 'compare' => '=' ); break; // default : // $query_args['meta_query'][] = array( // 'key' => 'affiliated_school', // 'value' => array_map( 'absint', explode( '-', $selected_range ) ), // 'compare' => 'BETWEEN', // 'type' => 'NUMERIC' // ); // break; } // This will show the 'reset' link add_filter( 'job_manager_get_listings_custom_filter', '__return_true' ); } } return $query_args; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Altering search Criteria’ is closed to new replies.