Skip Navigation

[Resolved] Prevent user from creating more than one custom post from a front-end form post

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to allow their clients to only create one post.

Solution:

This can be done by following the instructions in the link below.

https://toolset.com/lesson-placement/lesson-placements-1622969-1929573/?utm_source=pocket_mylist#how-do-i-prevent-users-from-creating-more-than-one-contractor-post

This support ticket is created 2 years, 6 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.

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 10 replies, has 2 voices.

Last updated by dominiqueM-3 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2189821

Tell us what you are trying to do?
I try to reproduce the steps of this course (https://toolset.com/lesson-placement/lesson-placements-1622969-1929573/?utm_source=pocket_mylist) which corresponds to what I need to set up for a future site.

Especially I've tried to prevent user from creating more than one custom post from a front-end form post as explained in the above mentioned course. The post is a business profile that must be unique.
I think I succeeded but I've noticed that it works only if the created post is published.
If you set up the post form to create a post with a status 'Pending review' it doesn't work for me: the post form is available more than once and user can create as many posts as he want to.
Could you confirm or did I make a mistake.
For my project, as created post must be validated by an admin, I would prefer it is saved as Pending review.

Tank you

#2190121

Shane
Supporter

Languages: English (English )

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

Screenshot 2021-10-07 at 2.16.44 PM.png

Hi Dominique,

I can confirm that it is checking if the user has posts that are published. If the user's posts are not published then they can create another post.

Perhaps you can try adding a post status query filter to the view to let it include posts that are pending as well. This should help as the view will check for posts that are published by default.

Thanks,
Shane

#2190623

Hi Shane,

Thank you for your support.

Unfortunately I could not manage both the publication of just one post and the Pending status.
What I did not mentioned is that I would like the user to be able to view and modify his post profile even if it is still in Pending status.
For now I can't do that if the post is Pending. it must be published.

Best regards

#2190909

Shane
Supporter

Languages: English (English )

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

Hi Dominique,

Thank you for the clarity. Why not allow the user's post to be published first then after you allow them to edit it ?

This can help to alleviate some of the issues that you're having.

Thanks,
Shane

#2190925

Hi Shane,

Sorry for not being able to give you all the information at once.
I would like profile posts, created from front-end post form, to be revised and approved by an admin before being visible in the site.
My idea is that if a post is approved, the admin change the status from pending to published in the back-end.
With the use of a third party plugin like BNFW a notification is sent to the author to let him know his profile is published.

Hope this is a bit more clear

Best regards

#2191037

Shane
Supporter

Languages: English (English )

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

Hi Dominique,

What you can do is to output the Edit Form in the view.

Lets say the user already created the account but the profile is in Pending. If you add the query filter to the view to filter it by the Post Status then you can now display the Pending Posts in the view.

Instead of displaying any post data you will display the form. Or you can add a conditional block in the view to check the status of the items being displayed.

So if the post status is Pending then you will display the edit form directly, however if the status is Published then you'll display the Profile but an edit post link that will then allow the user to edit their profile even after it is published.

Please let me know what you think of this.

Thanks,
Shane

#2192703

Hi Shane,

Thank you for your reply.
It is a great idea but unfortunately it doesn't solve the fact that a subscriber can still create as many profile posts as he wants to if profile post is in pending status (for example if he goes back to the url of the profile creation form).
The solution to display the profile creation form if no result is found in the view (as explained in the demo: https://toolset.com/lesson-placement/lesson-placements-1622969-1929573/?utm_source=pocket_mylist) only works if profiles are published.

#2192997

Hi Shane,

I tried again.
I didn't understand that I didn't need a page containing the professional profile (custom content type) creation form.
This is how I managed to get closer to the result I want:
- creation of Toolset forms for creating and editing the professional profile
- in a page creation of a view for professional profiles with 2 filters
'Select posts with the author the same as the current logged in user' and 'Select posts with status of publish or pending'
- addition of the shortcode referring to the form for creating a professional profile if the view does not contain any data (loop template metabox)
- in the view loop, addition of a condition that tests if the number of items in the view is > = 1 (as you suggested)
in this case display of a content template containing the professional profile with a link to edit it

I hope it's not too convoluted.

Please let me know what you think of this.
Regards,
Simon

#2193129

Shane
Supporter

Languages: English (English )

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

Hi Simon,

Yes this is the exact solution that I recommended. Are there any issues or is the user only able to create one post now.

Please let me know.
Thanks,
Shane

#2193145

Hi Shane,

According to my tests the user can actually create only one profile.
Since the creation form is not attached to any page and does not have a url, I do not see how the user could access it.
I hope I am not mistaken.
I am closing this ticket for now.
Thank you again for your help.

#2193147

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.