This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Use this hook to customize a filter for a View. This hook will only apply to filters you have added in the "Advanced Settings" section of your View. This hook is similar to the frm_where_filter hook, but is fired earlier and changes only the value used before it is used in the full database query.
Usage
add_filter('frm_filter_where_val', 'frm_filter_where_val', 8, 2); function frm_filter_where_val($where, $args)
Parameters
- $where (string) The value used in the filter
- $args (array) Includes 'display' (object), 'where_opt' (field id)
Examples
Check each value from checkbox
In order to use checkboxes in a search form, custom code is needed to separate each checked box and search for them individually instead of as a single string. For example, if I had a search form with boxes for 'red', 'blue', and 'yellow', I don’t want it to search for 'red, blue'. Replace 205 with the ID of your View. Replace 82, 83, and 84 with either a single field ID for the field in your View filter or multiple, comma-separated field IDs if you have multiple fields in your View filters that need this code.
This code example can be used for any situation where you want to search multiple, comma-separated values.
add_filter('frm_filter_where_val', 'frm_search_multiple_values', 8, 2);
function frm_search_multiple_values($where, $args){
if ( $args['display']->ID == 205 and in_array( $args['where_opt'], array( 82, 83, 84 ) ) ) {
$where = explode(', ', $where);
}
return $where;
}
Set a custom filter value
Use the code below to set a custom filter value from the URL. Change 205 to your View ID, 84 to the ID of the field in the filter, and param_name to the name of the custom parameter in your URL.
add_filter('frm_filter_where_val', 'my_custom_filter_value', 8, 2);
function my_custom_filter_value( $where, $args ) {
if ( $args['display']->ID == 205 && $args['where_opt'] == 84 && isset( $_GET['param_name'] ) && $_GET['param_name'] ) {
$where = $_GET['param_name'];
}
return $where;
}
Remove characters from filter value
Use the code below to remove specific characters from a value in a filter. Change 205 to your View ID and change 84 to the ID of the field in the filter.
add_filter('frm_filter_where_val', 'remove_characters_from_filter_value', 8, 2);
function remove_characters_from_filter_value( $where_value, $args ) {
if ( $args['display']->ID == 205 && $args['where_opt'] == 84 ) {
$where_value = str_replace( array( 'amp;' ), '', $where_value );
}
return $where_value;
}