Filter View on User ID

add_filter('frm_where_filter', 'my_unique_name_filter_custom_display', 10, 2);
function my_unique_name_filter_custom_display($where, $args){
	$view_id = bsn_get_post_id_from_slug('slug-of-view'); // replace 'slug-of-view' with your view slug
	$field_id = bsn_get_field_id_from_key('field-key'); // replace 'field-key' with your field's key
	if ( $args['display']->ID == $view_id && $args['where_opt'] == $field_id){ 
		$user_id = $_GET['trainer']; // change trainer to the name of the parameter in your URL
		if ( !is_numeric($user_id) ) {
			// if the username was in the url, get the ID
			$user_id = FrmProAppHelper::get_user_id_param($user_id);
		if ( is_numeric($user_id) ) {
			$where = ("meta_value = ". $user_id ." and'". $args['where_opt'] ."'");
		} else {
			// no matching user ID was found
			$where = ("meta_value = 1 and meta_value = 0 and'". $args['where_opt'] ."'");
	return $where;

if (!function_exists('bsn_get_post_id_from_slug')) {
	function bsn_get_post_id_from_slug($slug) {
		global $wpdb;
		$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$slug'");
		return $id;

if (!function_exists('bsn_get_field_id_from_key')) {
	function bsn_get_field_id_from_key($field_key) {
		global $frmdb, $wpdb;
		$field_id = $wpdb->get_var("SELECT id FROM $frmdb->fields WHERE field_key LIKE '".$field_key."'");
		return $field_id;

2 comments on “Filter View on User ID”

  1. Hi Darryl,

    I'm trying to use your code to filter a view by userid passed from the URL. I have set as following:

    slug-of-view: show-all-expenses
    field-key: the key of the hidden USERID Field
    trainer: empname

    With these settings, it is still showing me all entries instead of the entries just of the user specified in the URL. Do you have any ideas what I might be doing wrong?

    1. It may be that there's something wrong in my helper functions, $frmdb has been deprecated since this was written, and there have been other changes to Formidable Pro.

      Try hard-coding the IDs and removing the references to the helper functions.


      $view_id = ##; // id of your view
      $field_id = ## ;// id of your field

Leave a Reply

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

I accept the Privacy Policy

Recent Posts

October 5, 2020
Easy Ways To Automate Your Website - 2 approaches

Isn't technology supposed to make life easier? I recently built a tool for a provider of an ERP system, to allow his clients to automatically publish inventory to their business websites and keep the sites in synch with his system. It got me thinking (again) about automation, and how business can do more with tools they're already using.

June 17, 2020
The Pivot: Making the shift from Commodity to Consultant

A lot of people - even companies - that provide technical services find themselves in the unfortunate position of being viewed as "the techs" and ignored when discussion turns to policy, marketing, or other topics relating to business management and strategy - the domain of consultants. This can be the case whether the tech is a twenty-something fresh out of school, or someone who's been in the industry for decades.
It's difficult to change people's perception once you've been slotted into a role. Far better to set expectations at the beginning of a relationship than try to change mid-stride.

June 4, 2020
An office without walls. A business without borders. There's no need to meet in person.

I should have known better, but I was hit with a wave of panic when the government announced the beginning of the corona virus lock down. I thought that might be it for my business. How would I get new clients? What about the meetings I had already scheduled? What if everybody stopped spending? Even in a digital business it's sometimes difficult to see past traditional expectations.

To my eternal relief, I learned better.

May 29, 2020
Your Website is an Investment, NOT an Expense. Demand ROI

Viewing your website(s) as a necessary expense rather than as an investment that's expected to produce a return is a critical misstep. Business owners often have a difficult time defining the role of their Website in their online presence and marketing. People often confess to feeling overwhelmed by technology, and rather than deal with the complexity, they settle for a site that's less functional than a business card or a billboard.

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

Email sending image

You have Successfully Subscribed!