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.
The frm_filter_view hook allows you to modify any part of the View object before the View is rendered.
Usage
add_filter( 'frm_filter_view', 'change_my_view_object', 10, 1);
Parameters
- $view (object)
Examples
Change View order based on URL parameter
Use the following code to change a View's order when a specific URL parameter and value are set. Replace 123 with the ID of your View, replace my_param with your parameter name, replace custom_value with your specific parameter value, and replace 150 with the ID of the field you want to order by.
add_filter( 'frm_filter_view', 'change_my_view_object', 10, 1);
function change_my_view_object( $view ) {
if ( $view->ID === 123 ) {
if ( isset( $_GET['my_param'] ) && $_GET['my_param'] == 'custom_value' ) {
$view->frm_order_by = array( 150 );
$view->frm_order = array( 'DESC' );
}
}
return $view;
}
Check if a user exists or not
Use the following code to have a View that shows items connected to a user existing in the database.
add_filter('frm_filter_view', 'check_if_users_exists', 10, 2);
function check_if_users_exists( $view ) {
$target_view_id = 380; // change this to your View ID.
if ( $target_view_id !== (int) $view->ID ) {
return $view;
}
$target_form_id = $view->frm_form_id;
global $wpdb;
$item_ids = FrmDb::get_col( $wpdb->prefix . 'frm_items i INNER JOIN ' . $wpdb->prefix . 'users u ON u.ID = i.user_id', array( 'i.form_id' => $target_form_id ), 'i.id' );
$view->frm_where = array( 'id' );
$view->frm_where_is = array( 'in' );
$view->frm_where_val = array( implode( ',', $item_ids ) );
return $view;
}
If you want to make a View that only shows the users that don't exist, change this line of code:
$view->frm_where_is = array( 'in' );
to
$view->frm_where_is = array( 'not in' );