Inicio › Toolset Professional Support › [Resuelto] limit the max number of relationships per user
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Este tema contiene 13 respuestas, tiene 2 mensajes.
Última actualización por jesusM-6 hace 1 año, 6 meses.
Asistido por: Minesh.
I need to limit the max number of relationships per user. Example: I have one to many relationship: grupo->obra. All user can create 1 group and I want restrict the number of obras each user can create. Thanks
Hello. Thank you for contacting the Toolset support.
I would like to know - are you looking to restrict the number of relationships per user from frontend form or from backend post add/edit page?
There are 2 user roles: author and universidad
There are 2 CPT: grupos and obras
Users "universidad" can submit the form to create a pending CPT "obra". Then the group to which the CPT Obra belongs can approve it (to publish the cpt) using another form. The form where I have to control the number of relations depending on the user who sends it is the following.
The option to display the form depending on whether the conditions are met or not is not useful for me, since in this way the user could open several browser tabs (the condition is met) and then send all of them. The check would have to be done after the form is submitted and before it is added to the database.
This is the form which is submitted by user "universidad" to request a cpt "obra" related to cpt "grupo" that belongs to a user with author role :
With a content form
[credform class='cred-form cred-keep-original'] [cred_field field='form_messages' value='' class='alert alert-warning'] [cred_field field='post_title' post='contrataciones-1' value='Contratación: [wpv-user field="display_name"] contrata [wpv-post-title]' urlparam='' class='form-control' output='bootstrap'] [cred_field field='obra-contratada' post='contrataciones-1' value='[wpv-post-title]' urlparam='' class='form-control' output='bootstrap'] <div class='row border border-dark p-2 m-0 mb-3'> <div class='col-md-4'><strong>Grupo: </strong>[wpv-post-title id="$grupo"]</div> <div class='col-md-4'><strong>Teléfono: </strong>[types field='telefono' separator=', ' id='$grupo'][/types]</div> <div class='col-md-4'><strong>Email: </strong>[types field='email' separator=', ' id='$grupo'][/types]</div> </div> [cred_generic_field field="email_grupo" type="email" class="" urlparam=""] { "required":0, "validate_format":0, "persist":1, "default":"[wpv-user field="user_email" id="[wpv-post-author format='meta' meta='ID']"]" } [/cred_generic_field] [cred_field field='fecha-de-la-actuacion' post='contrataciones-1' value='' urlparam='' class='form-control' output='bootstrap' required="true"] [cred_field field='localidad' post='contrataciones-1' value='' urlparam='' class='form-control' output='bootstrap' required="true"] [cred_field field='recinto' post='contrataciones-1' value='' urlparam='' class='form-control' output='bootstrap' required="false"] [cred_field field='_wpcf_belongs_grupo_id' value = "[wpv-post-id id='$grupo']" readonly = "true" class='form-control' output='bootstrap'] <div class="form-group d-none"> <label>Universidad Popular que contrata</label> [cred_field field='_wpcf_belongs_universidad-popular_id' value='[id_univ_usuario]' class='form-control' output='bootstrap'] </div> [cred_field field='form_submit' value='Solicitar contratación de: [wpv-post-title]' urlparam='' class='btn btn-success btn-lg' output='bootstrap'] [/credform]
You can use the "cred_form_validate" to validate the form where we can check how many connections are made by the current loggedin user, if its more than three then we can display the error message.
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
or even before displaying the form we can check how many connections available for current author and based on that we can show/hide the form.
If you can tell how how exactly you would like to go and share problem URL where you added the form as well as admin access details I'm happy to help.
Please share admin as well as author user account details for frontend user.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
When I try to login it says its incorrect login access details.
Can you please send me working admin access details as well as please share frontend user "author" role user access details.
In addition to that I noticed that you are using the legacy way to get the parent but you must use the latest post relationship method. I will check once I get the admin access details and frontend user access details.
I have set the next reply to private which means only you and I have access to it.
Can you retry to access? I have disallow some defender rules. Thanks.
Thank you, login works now.
I would like to know you can create the new entries using the following form:
enlace oculto
Do you want to restrict the users creating new entries for the above form? if yes, how many entries you would like to allow?
Yes, i want restrict depending of the user. Not the same number for all users.
Can you describe for what user based on what role you want to restrict with what count?
It must depend on the number of relationship of the user logged in (role universidad) and the numbers of the relationships of the user thats belong the cpt obra where the form is displayed (role author)
Can you please share example based on that I will be able to offer you the solution as without that information I will not be able to guide you in the right direction.
You can setup test example and tell me on what action you want to hide based on what role and how many posts.
I need to limit the number of cpt contrataciones depending on each user. The form ID where users universidad can create CPT contrataciones is 523. Before submit the form I need check the number of CPT contrataciones of the users related (user universidad who submits the form and user author who is related the CPT obra where the form is displayed).
I understand that you want to limit the number of posts but at what count and for what post type and for what user role.
How many posts you want to allow the author user to create?
Can you please share more details with both user role author and universidad and tell me the steps I will have to follow and at what point what user will do what action and what posts for what post type you want to restrict with what count.
My issue is resolved now. Thank you!