WP Job Manager – Added a salary field, having issue with reset button

I am using WP Job Manager and have added a salary filed using the tutorial on their website: https://wpjobmanager.com/document/tutorial-adding-a-salary-field-for-jobs/. It works perfectly except it does not add the reset button like the other search/filter items do. I am wondering if anyone else has come across the same issue and would know a solution. There is a line in their example that says “This will show the ‘reset’ link” but it is not working. The code I am using:

add_filter( ‘submit_job_form_fields’, ‘frontend_add_salary_field’ );

function frontend_add_salary_field( $fields ) {
$fields[‘job’][‘job_salary’] = array(
‘label’ => __( ‘Salary ($)’, ‘job_manager’ ),
‘type’ => ‘text’,
‘required’ => true,
‘placeholder’ => ‘e.g. 20000’,
‘priority’ => 7
);
return $fields;
}

add_filter( ‘job_manager_job_listing_data_fields’, ‘admin_add_salary_field’ );

function admin_add_salary_field( $fields ) {
$fields[‘_job_salary’] = array(
‘label’ => __( ‘Salary ($)’, ‘job_manager’ ),
‘type’ => ‘text’,
‘placeholder’ => ‘e.g. 20000’,
‘description’ => ”
);
return $fields;
}

add_action( ‘job_manager_job_filters_search_jobs_end’,
‘filter_by_salary_field’ );
function filter_by_salary_field() {
?>
<div class=”search_categories”>
<label for=”search_categories”><?php _e( ‘Salary’, ‘wp-job-manager’
); ?></label>
<select name=”filter_by_salary” class=”job-manager-filter”>
<option value=””><?php _e( ‘Any Salary’, ‘wp-job-manager’ ); ?>
</option>
<option value=”upto20″><?php _e( ‘Up to $20,000’, ‘wp-job-manager’ ); ?></option>
<option value=”20000-40000″><?php _e( ‘$20,000 to $40,000’, ‘wp-job-manager’ ); ?></option>
<option value=”40000-60000″><?php _e( ‘$40,000 to $60,000’, ‘wp-job-manager’ ); ?></option>
<option value=”over60″><?php _e( ‘$60,000+’, ‘wp-job-manager’ ); ?></option>
</select>
</div>
}

/**
* This code gets your posted field and modifies the job search query
*/
add_filter( ‘job_manager_get_listings’,
‘filter_by_salary_field_query_args’, 10, 2 );
function filter_by_salary_field_query_args( $query_args, $args ) {
if ( isset( $_POST[‘form_data’] ) ) {
parse_str( $_POST[‘form_data’], $form_data );
// If this is set, we are filtering by salary
if ( ! empty( $form_data[‘filter_by_salary’] ) ) {
$selected_range = sanitize_text_field( $form_data[‘filter_by_salary’] );
switch ( $selected_range ) {
case ‘upto20’ :
$query_args[‘meta_query’][] = array(
‘key’ => ‘_job_salary’,
‘value’ => ‘20000’,
‘compare’ => ‘<‘,
‘type’ => ‘NUMERIC’
);
break;
case ‘over60’ :
$query_args[‘meta_query’][] = array(
‘key’ => ‘_job_salary’,
‘value’ => ‘60000’,
‘compare’ => ‘>=’,
‘type’ => ‘NUMERIC’
);
break;
default :
$query_args[‘meta_query’][] = array(
‘key’ => ‘_job_salary’,
‘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;
}

Read more here:: WP Job Manager – Added a salary field, having issue with reset button

Leave a Reply

Your email address will not be published. Required fields are marked *