Skip to content

Instantly share code, notes, and snippets.

@wpmark
Created Jan 17, 2020
Embed
What would you like to do?
Altering the meta compare value of the WP Broadbean Search salary field.
This function will change the behaviour of the salary field in the WP Broadbean Search form. By default the salary search only searches for values greater than whatever the user enters.
The code above changes the behaviour of this to return jobs that have salary values greater than AND equal to the value entered.
Place this code either in your themes functions.php file, your own plugin, or a file in the mu-plugins folder inside the wp-content folder.
<?php
/**
* Edits the compare value for the salary meta field in the search form to greater than or equal to.
*
* @param array $fields The current array of meta search fields in the search form.
* @return array The modified array of meta search fields in the search form.
*/
function hd_alter_salary_meta_search_compare( $fields ) {
// if we have a job salary field.
if ( ! empty( $fields['wpbb_job_salary'] ) ) {
// change the comapre to greater than or equal.
$fields['wpbb_job_salary']['compare'] = '>=';
}
// return the modified fields.
return $fields;
}
add_filter( 'wpbb_search_meta_search_fields', 'hd_alter_salary_meta_search_compare', 20, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment