Skip Navigation

[Resolved] List Users added by current logged in User

This support ticket is created 2 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.25 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Paul 2 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#2287795

Hi there,

I am working on a school website which allows multiple Schools to register.

What I want to do is to allow each school to add Teachers as new users. That's fine and I can do that with Views and CRED.

However, in the schools "dashboard", I only want to show the Teachers added by the current logged in user, not all Teachers added by anyone.

The problem is, you can add a filter "filter by post author" for normal posts but not for Users.

Can you help me with a solution?

#2287815

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for getting in touch.

Unfortunately this won't be possible as a relationship as you describe doesn't exist in the users table to determine which user created another.

The only way you can do this is that if you create a user's profile using a custom post type, then the user who creates the profile can filter for all the profile posts they created.

If this is done with purely the wordpress users then this won't be possible to do.

Thanks,
Shane

#2287915

Hi Shane,

Would there be a CRED function I could use to assign the Current logged in user ID to a custom field against a new user being added? Then I could reference that field in a view to only list users with a specific ID. Would this be possible?

#2288051

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

That is possible to do as you can update a user meta when its being created.

You can create a single line field called created by and from there you can update this custom field with the ID of the user creating the Teacher.

The CRED hook that you should be looking at is.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($user_id, $form_data)
{
$current_user_id = get_current_user_id();

    // if a specific form
    if ($form_data['id']==12)
    {
        if (!empty($current_user_id))
        {
            // add it to saved user meta
            update_user_meta($user_id, 'my_custom_field', $current_user_id, true);
        }
    }
}

Replace 12 with the ID of your form and replace 'my_custom_field' with the slug of your custom field keeping the wpcf- prefix.

Thanks,
Shane

#2288687

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.