Skip Navigation

[Résolu] Limit users to 1 child post creation

This support ticket is created Il y a 4 années et 7 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par marioD-5 Il y a 4 années et 7 mois.

Assisté par: Jamal.

Auteur
Publications
#1571551

Hello,

I spent a few days searching these forums and I don't seem to find a solution. Please excuse me if this has been resolved somewhere and skipped my attention.

I'm building a staffing agency website where customers can place a job and employees apply to them.
I have a parent CPT called JOBS and a child CPT called APPLICATION.

I'm trying to limit the number of applications to 1 per user.

What might help me is one of these options:

A- a way to detect the number of posts the current user has for the current child post (if 0 allow if 1 hide)

OR

B- I embedded the APPLICATION cred inside a view list of JOBS and hid all fields except the submit button. I also created a custom field called JOB_STATUS on the APPLICATION cpt with value 1 or 0. If a user already applied to a job, this field should exist and have default value of 1. I am unable to read the value from the view list.

Here is my conditional code:
[wpv-conditional if="( '[wpv-post-taxonomy type='level' show='slug' format='slug']' eq '[wpv-current-user info='role' show='slug' format='slug']' )"]

<td>[wpv-post-id]</td>
<td>[wpv-post-link]<br>[types field='job-notes'][/types]</td>
<td>[wpv-post-author]</td>
<td>[types field='start' style='text' format='F j, Y (g:i A)'][/types]</td>
<td>[types field='finish' style='text' format='F j, Y (g:i A)'][/types]</td>
<td>
[wpv-conditional if="( $(wpcf-status) eq '2' ) OR ( $(wpcf-status) eq '3' ) OR ( $(wpcf-status) eq '4' )"]You can't apply to this job[/wpv-conditional]
[wpv-conditional if="( $(wpcf-status) eq '1' ) "][cred_form form="apply-form"][/wpv-conditional]

</td>

<td>[types field="job-status"][/types]</td>
[/wpv-conditional]

OR

C- if you propose a smarter way to achieve this. I only need users to apply once.

My website link is lien caché

Thank you,

#1572339

Hello and thank you for contacting the Toolset support.

Option (A) is good as it will be used on jobs view to display/hide the "Apply" button, and in the validation of the application submission. Option (B) is only handling the "Apply" button display. If a user knows how to build an HTTP payload to create a new application, it will be created because no validation to limit submission count is done.

I would like to focus on the title of this ticket "Limit users to 1 child post creation". Right now, with Toolset, there is no built-in solution to this. It needs custom code to hook the form validation and check if the user has already applied to the parent job or not. The hook to use is cred_form_validate
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
Here are some examples that limit the user to one submission but that does not include a parent post:
- lien caché
- https://toolset.com/forums/topic/limit-the-number-of-cred-form-submissions/
- https://toolset.com/forums/topic/limit-the-count-of-submission-form-one-post-per-role/

The following examples use a function to count the existing post, similar to your option (A), then we can use the function inside our hook to cred_form_validate
- https://toolset.com/forums/topic/limit-the-number-of-posts-submitted-by-registered-customers/#post-368894
- https://toolset.com/forums/topic/i-am-trying-to-limit-the-number-of-posts-the-user-can-submit-in-a-certain-post-t/

You can use the Post Relationships API functions to scope the search to the parent job post.
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

Regarding option (B), if you build the function to count the user application of the option (A), you can use it directly inside a conditional shortcode. Check more about it here https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-custom-functions-in-conditions/

I hope this helps. Let me know if you have any doubts.

#1572579

Thank you Jamal for the detailed answer.

Luckily, I found a solution before you posted the answer.

I used a hidden custom field called STATUS with 2 states (Applied/Available).
On create event, the default state of STATUS is saved as APPLIED.
On the view, if state is APPLIED the button is hidden.

I then added a cancel application button in the account page:
[cred_delete_post_link text='Cancel application' message='Are you sure you want to delete your application?' message_show='1' action='trash']

Since my site is only accessible to logged-in users, I don't suppose it will be vulnerable to users goofing around with URL payloads.

Thank you for your support, these forums are extremely helpful.