user-meta filter

By: Stig Tuastad | Asked: 11/26/2023
ForumsCategory: How-touser-meta filter
Stig Tuastad asked 11 months ago

Hi I have used days trying to figure out why i cannot filter my view based on a user_meta in my form view. I have a meta field for some of the users reffering to their company. When I filter the view with ´Company equals [user_meta Key=Company]´ no results show, either as admin or as logged in user. The filter works fine when i write a company name. Is there some settings or connections i have to set up for this function to work in my view.     

2 Answers
Victor Font answered 11 months ago
The Formidable KnowledgeBase Advanced Filtering shows an example with "Key" in lowercase like this: [user_meta key=user_age]. Have you tried variations testing for case sensitivity?
Victor Font replied 11 months ago

And, are you absolutely sure the test users are logged in and the key/value pair exists in the wp_usermeta table for the logged in user id?

Last, does the user id saved in the entry match the logged in user id?

Stig Tuastad answered 11 months ago
Thanks for your response! :) I am confident that the user is logged in, and the corresponding value exists. I have also ensured the usage of lowercase (and tested all variations) in the meta reference.   However, I'm struggling to comprehend the following: Does the user ID stored in the entry match the ID of the currently logged-in user? My objective is to display a list of equipment certificates issued to a specific company for all their staff members with access to the site to see. Users have the Company name in their metadata. The user ID stored in the entry belongs to me, as I am responsible for issuing and registering these certificates - this make the reference to user ID confusing. (There are private users without company name - I hope this is not crashing a data filter?)   While the logic of linking a value in a table to a user's metadata is straightforward, I suspect that a reference to the user needs to be established somewhere in the view. Unfortunately, I am unable to determine how to set up this reference (if needed).   Any suggestions would be appreciated! - I'm tearing my hair out here...        
Victor Font replied 11 months ago

WordPress user IDs stored with entries belong to the logged in user entering the data. The logged in user is always regarded as current_user.

Your design requires you to store a different element in the entry to serve as your view filter. You cannot depend on user IDs. I also wouldn't depend on the user_meta shortcode as a view filter parameter unless I was passing the user meta to view as a parameter and using [get param] in place of [user_meta]

If this were my project, I probably would have created a company lookup form and use dynamic fields for the certificates. Here's why. When you use lookup records with dynamic fields, Formidable stores the entry ID of the lookup record. If you have 100 people working in the same company with access to the same data, if you store the Company value for all 100 staff, what happens if the company name changes or you notice a spelling error after the fact? You have to modify 100 individual records to apply the correction or do it through SQL and manipulating the database directly.

If you encountered the same scenario with lookup tables and dynamic fields, you only have to edit the record in the lookup table once and all 100 employees are immediately updated across the system. The link to the lookup table with dynamic fields is more or less permanent and makes it a whole lot easier to use data common to many users that is not a user id. Please consider rethinking your design.

Stig Tuastad replied 11 months ago

Thanks!
I'm familiar with normalization of databases, but i don't quite understand how this works is in Formidable. I have a Company table (form) and are using lookup to fetch the company name. (in fact i also have a location form feching both company and location from this. I do the same for equipment makes and models and pull everything togeher in my certificate overview page. In this everything looks like it in plain text when stored to the table.

I have tried to understand where i should put any code for a function like [get_param] and how to do this. I think the best solution would be to somehow ask for only the data where company name equals the users Companyname. This is for me the core functiality in a databse and I have looked for a easy plug and play solution for this. I guess some shortcode is needed - I am looking for a step by step explanation on shortcodes, but can't find this

Stig Tuastad replied 11 months ago

Thanks!
I'm familiar with normalization of databases, but i don't quite understand how this works is in Formidable. I have a Company table (form) and are using lookup to fetch the company name. (in fact i also have a location form feching both company and location from this. I do the same for equipment makes and models and pull everything togeher in my certificate overview page. In this everything looks like it in plain text when stored to the table.

I have tried to understand where i should put any code for a function like [get_param] and how to do this. I think the best solution would be to somehow ask for only the data where company name equals the users Companyname. This is for me the core functiality in a databse and I have looked for a easy plug and play solution for this. I guess some shortcode is needed - I am looking for a step by step explanation on shortcodes, but can't find this

Victor Font replied 11 months ago

Neither WordPress nor Formidable use normalized table structures. They use the metadata schema.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right