Passer la navigation

[Résolu] Split: is there a way to limit the number of profiles a user can create?

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

The customer wanted to prevent a user from creating more than one Profile post, while still allowing the same user to create multiple Event posts.

Solution:

There is no single setting for this, but it can be controlled per post type. The recommended approach was to show the Create Profile form only when the logged-in user does not already have a Profile post. This was done by using a View filtered by post author equals the logged-in user, and placing the profile creation form inside that View’s loop template. This limits Profiles to one per user without affecting Event creation.

Relevant Documentation:

https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/

This support ticket is created Il y a 2 weeks. 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.

Ce sujet contient 1 reply, a 0 voix.

Dernière mise à jour par Christopher Amirian Il y a 2 weeks.

Assisté par: Christopher Amirian.

Auteur
Publications
#2866959

Hi again!

A new question has come up: is there a way to limit the number of profiles a user can create?

What I *don't* want is for a single user to be able to create multiple profiles. However, I *do* want a user to be able to create multiple events.

Thanks in advance.

#2866962

Christopher Amirian
Supporter

Les langues: Anglais (English )

Hi,

Welcome back. There's no single on/off setting for this, but the limit is applied per post type, so you can cap Profiles at one each while leaving Events unlimited.

To limit Profiles to one per user, hide the Create Profile form from anyone who already has a profile:

1. Create the page where users go to create their profile.
2. On that page, add a View that lists the Profile post type. Select the View block, and in the right sidebar under Content Selection → Add a filter, choose the Post author filter set to Post author is the same as the logged in user.
3. Don't put any blocks in the loop itself. Select the View Loop block, open the Loop Template section in the sidebar, and insert your form shortcode there:

[cred_form form="your-form-slug"]

Replace your-form-slug with your Create Profile form's slug (visible when you edit the form).

The effect is that the form is tied to the per-user profile check, so a user who already has a profile no longer gets the create form.

Please check this documentation for the details:

https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/ (see the section "How do I prevent users from creating more than one Contractor post?")

Thanks.