Limit autosugesstion to users with specific meta value


Home Forums Front End PM PRO Limit autosugesstion to users with specific meta value

This topic is: Resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38747
    simon uria
    Participant

    Hello Shamim,

    I use your plugin so that users of the “Mentor” type can write messages to their “students”. However, all users are displayed in the recipient autosugesstion. I would like to limit this to the students who have a meta-value with the ID of the mentor in their user profile.
    Is it possible to limit the autosuggestion of the recipient so that the mentors only see their own students?

    Thanks and best regards
    Simon

    #38752
    Shamim Hasan
    Keymaster

    You can add following code in your theme’s (child theme’s if you are using) functions.php

    add_filter( 'fep_filter_rest_users_args', function( $args ){
        if ( in_array( 'mentor', wp_get_current_user()->roles )  ) {
            $args['meta_query'][] = [
                'key' => 'mentor',
                'value' => get_current_user_id(),
            ];
        }
        return $args;
    });
    

    (untested)
    Change mentor role and meta key in the code as you require.
    Let me know.

    #38764
    simon uria
    Participant

    Shamim, you made my day!
    Thank you very much for the very well working snippet.

    Kind regards
    Simon

Viewing 3 posts - 1 through 3 (of 3 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.