Skip to content

Instantly share code, notes, and snippets.

@cmehrabian
Last active November 27, 2015 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmehrabian/a5d1085061b1e0d17c48 to your computer and use it in GitHub Desktop.
Save cmehrabian/a5d1085061b1e0d17c48 to your computer and use it in GitHub Desktop.
Jobify - Search filter by school affiliation
add_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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment