Skip Navigation

[Resolved] Auto assign parent post to a childpost of a user (only one parent post per user)

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

Problem: I have a CRED form that is used to create Location posts, which are children of Business posts. There is a select field that allows a User to select a parent Business, but I want the options to be limited to show only Businesses created by the current User.

Solution: Follow the guide here to create a child post link from the parent Business post. This will automatically set the parent Business ID for you. See "Displaying the Form" section at the documentation link below.

Relevant Documentation: https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

This support ticket is created 7 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#555304
Screen Shot 2017-08-01 at 17.46.53.png

I have a posttype "business" of which each user will always have exactly 1. I have a form setup for users to add "locations" which is a childpost of "business".

At the bottom of the CRED form (see attached screenshot) there is a dropdown to assign the location to a business.

The problem is:

In the dropdown, all businesses including the ones from other users are shown but it should either be:

A: The dropdown only shows the business that the currently logged in user created
or
B: The location is automatically assigned to the business of the currently logged in user.

I know that I could simply hide it using css but later on I will need to create a view for the admin where he has an overview of all the business and the locations assigned to each business/user.

Any ideas? 🙂

#555356

There are a few ways to do this.
1. If you are displaying this form on its own page, you can follow the guide here to create a child post link from the Business page. This will automatically set the parent Business ID for you. See "Displaying the Form" section here: https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

2. If you are displaying this form in the Content Template or Layout of another post, you can set the value of this field using the "value" attribute in your CRED form editor. This will require knowing the ID of the Business post you want to use as the parent of the new Location. One easy way to do this is to create a custom field on each User that contains the Business ID that was automatically created for them. You could automate this in the same cred_save_data hook that creates the Business. Then you can get the Business ID using a wpv-user shortcode.

Which option is better for your site?

#555673

Option 1 worked like a charm 🙂