Lookup - Ignore Watch filter

By: Chris Titus | Asked: 02/15/2023
ForumsCategory: Code HelpLookup - Ignore Watch filter
Chris Titus asked 1 year ago

I have a form that uses a Lookup field to insert Company Name from another form. It uses a Watch filter to only pull the companies assigned to the specific employee using the form. I would like to ignore this rule for the Admin so the Admin can submit for any and all companies. Is there some PHP code that could help with this?   Thanks for your help, Chris

4 Answers
Bobby Clapp answered 1 year ago
Chris Titus replied 1 year ago

Thanks Bobby. I had actually tried this, but it didn't work for me. I'm not using a current_user filter. I'll paste an image below of the filter I'm trying to ignore.

Chris Titus answered 1 year ago
This is the Lookup - Watch filter that I'm trying to ignore (pls see image).
Attachments
Walter JonesWalter Jones replied 1 year ago

Can’t you just delete that watch then?

Chris Titus replied 1 year ago

Unfortunately, I cannot b/c this form is being used by both the Admin and the Account Executives. The AEs are only able to see the clients assigned to them, whereas the admin should be able to see all clients when adding entries in this specific form.

Chris Titus answered 1 year ago
bump - Any add'l suggestions here would be greatly appreciated.
Walter JonesWalter Jones answered 1 year ago
Haven’t been able to test this, but taking a stab at it:  create a code snippet using the code below.  Make sure you change the field ID of the lookup field.
function change_lookup_options( $options, $args ) {
    $user = wp_get_current_user();
    
    // Check if the user is an administrator
    if ( in_array( 'administrator', $user->roles ) ) {
        
        // Check if the Lookup filters are being applied to the specified field
        if ( $args['field']->id == <FIELD_ID> ) {
            
            // Remove the Lookup filters
            $options = array();
        }
    }
    
    return $options;
}

add_filter( 'frm_filtered_lookup_options', 'change_lookup_options', 10, 2 );
 
Walter JonesWalter Jones replied 1 year ago

I tested this now, and it doesn't appear to be working, sorry I will keep trying at it when I have time.

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