[Resolved] Disallow users to “sign-up” repeatedly to the same “special activity”
This thread is resolved. Here is a description of the problem and solution.
Problem: I would like to prevent my site Users from creating more than one child post for a given parent post.
Solution: Create a Form that creates new child posts. Create a View of child posts, filtered by post author, where the author is the same as the current logged-in User, and also filtered by post relationship as related items of the post where the View is shown. In the "no results found" section of the View of child posts, insert the Form to create new child posts. Now the Form is only shown to those Users who have not yet created a child post for the current parent post.
The problem is that a user can subscribe several times to the same activity (i.e. they can create several custom posts of a certain type, which will be children of the same parent).
In my case, users are voluntaries and NGO's. NGO's have a custom post type called A, where they describe their project and there is a cred form for voluntaries to "sign-up" by creating a child post of type B (names are just for exemplification). A user X creates, by using that cred form, a B-type post, having the title "X-voluntary-name" and which whatever fields were extracted from the user profile. Up to here, no problem.
The problem appears when the same user X he logs out and re-logins, he will be able to "sign-up" again to the same project, i.e. create another child custom post type of the same parent, this time named "X-voluntary-name-1" and so on.
Question: how can I restrict this happening? I mention that one voluntary may subscribe to different projects, so it does not make sense to restrict the absolute number of custom posts he can create. I need a method for a user to be able to create exactly one children C1 of type B for a specific post P1 (of type A), and also create exactly one children C2 of type B for the specific post P2 (of type A). I do not want to let him create two children C1a and C1b of a custom post P1...
Hi, if I understand correctly you can accomplish this with a View of the child post type, filtered by post relationship and post author. Let me explain step by step:
- Create a new View, and choose "Display all results" in the popup.
- Select the child post type in the Content Selection area.
- If you cannot find the Query Filter panel in the View editor screen, click "Screen Options" in the top right corner of the page to activate the Query Filter panel.
- Add a post relationship Query Filter and choose the relevant relationship between the parent and child post type, where the parent is set by the post where this View is shown. See the screenshot here for an example where Books are the parent and Chapters are the child.
- Add a post author Query Filter, where the post author is the current, logged-in User.
- In the Loop Editor, click Skip Wizard to bypass the loop wizard.
- In the "No results found" section, delete that text and replace it with the Form to create a new child post. You can insert that by clicking the Toolset Forms button above the editor.
- In the main wpv-loop tags, do not insert any content, or insert whatever content you would like to display when the author has already created one child post.
- In the parent post or parent post template, remove the Form to create new child posts and replace it with your new View. This basically creates a conditional that displays the Form to create new child posts only if the current User has not yet created a child of the current parent post.
Let me know if this is unclear and I can try to give more guidance.