Docs & Support

Learn about all the Formidable features and get support from our amazing customer success team.

frm_where_filter

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. Please note that this hook is not designed to work with post fields or custom fields. A full database call is necessary to make this work with post or custom fields.

Usage

add_filter('frm_where_filter', 'filter_custom_display', 10, 2);
function filter_custom_display($where, $args)

Parameters

  • $where (array)
  • $args (array) => ['where_opt' (string), 'where_is' (string), 'where_val' (string), 'form_id' (integer)]

Examples

Stop user ID filter for admins

If you are filtering your view to show the user their own entries, but you would like the admin to see all entries, you can remove the query conditionally.

add_filter('frm_where_filter', 'stop_filter_for_admin', 10, 2);
function stop_filter_for_admin( $where, $args ) {
  if ( $args['display']->ID == 3 && $args['where_opt'] == 25 ) { //change 3 to the ID of your View and change 25 to the ID of your user ID field
    if ( current_user_can('administrator') ) {
      $where = "fi.id='". $args['where_opt'] ."'";
    }
  }
  return $where;
}

Filter by User ID in Dynamic field

This code can be used to allow filtering of a View with a Dynamic field that contains UserIDs. This custom filter will make sure the User ID in the Dynamic field is equal to the current user. This code will only be used if you have added a filter to your View that says "Dynamic field is equal to custom".

add_filter('frm_where_filter', 'filter_by_linked_id', 10, 2);
function filter_by_linked_id($where, $args){
if ( $args['display']->ID == 3 && $args['where_opt'] == 25){ //change 3 to the ID of your View and change 25 to the ID of your Dynamic field
global $wpdb, $user_ID;
$entry_id = $wpdb->get_col( $wpdb->prepare( "Select id from {$wpdb->prefix}frm_items where user_id=%d and form_id=%d", $user_ID, 5 ) );
//Change 5 to the id of the form linked through your data from entries field
if(is_array($entry_id) and count($entry_id) == 1)
$entry_id = reset($entry_id);
if(!$entry_id)
$where = "meta_value=1 and meta_value=0 and fi.id='". $args['where_opt'] ."'";
else if(is_array($entry_id))
$where = "meta_value in (". implode(',', $entry_id) .") and fi.id='". $args['where_opt'] ."'";
else
$where = "(meta_value = ". (int)$entry_id ." OR meta_value LIKE '%". (int)$entry_id .""%') and fi.id='". $args['where_opt'] ."'";
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2025 Strategy11, LLC. Formidable Forms® is a registered trademark Strategy11, LLC.

    Complete your purchase
    Special offer unlocked.
    Get 55% OFF!
    Complete Purchase
    Join 400,000+ using Formidable Forms to create form-focused solutions fast. Get Formidable Forms