Skip Navigation

[Resolved] Set parent post automatically in a child form

This support ticket is created 3 years, 8 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
- 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)

This topic contains 5 replies, has 2 voices.

Last updated by tualntM 3 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2168121
Create-e-new-Job-–-My-Blog.png

Is there any documentation that you are following?
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/#creating-forms-when-a-parent-post-is-preselected

p.s. The above documentation works when Edit child link is placed at Jobs single post.

----------------------------
My current CPT:
- Employers
- Jobs
- Applicants
----------------------------
Relationships:
- Applications (a Jobs -> Applicants, n..m) Relationship Intermediary post. Slug: application
- Employers -> Jobs do have, 1..n. Slug: employer-jobs
----------------------------
What I have so far,
1. User created (Role: Employer), at the same time a Profile Post type: Employer, is also created vie cred api (cred_save_hook).
2. Post forms, Create/Edit a job
3. Given Access for users type Employer to Create/Edit the above-mentioned forms.
4. Created a My Account page.
----------------------------

What I want to achieve:
- Adding a link at "My account" Page: "Create a new Job" and, when doing so, to connect it automatically with the Employer profile (already created).

So the "Employers - Jobs" field to be automatically selected. (the profile) [Screenshot attached]
- Employers -> Jobs do have 1..n Relationship.

Anytime an Employer creates a Job, it has to be connected with it's Profile.

Can you please guide me how to achieve this?

#2168711

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean that you want to hide/remove the parent field from your form and then when user submit the form you want to automatically link the current employee profile?

#2168713

Exactly - so when an Employer user submits a new Job to connect it with it's own Profile cpt. (Employer - Jobs are related One to Many).

I've tried the instructions in the following topic but that didn't work either.
https://toolset.com/forums/topic/i-need-to-automatically-set-the-related-post-directly/

#2168719

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL and admin access details as well as the employer user profile access details and share the details from what link I can submit the form.

*** 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.

#2168823

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've created the following view to get the ID of current loggedin employer post:
=> hidden link

Then within your form I've added the generic field as given under:

[cred_generic_field type='hidden' field='@employer-job.parent']
{
"default":"[wpv-view name="get-current-employer-post"]"
}
[/cred_generic_field]

Where as you can see the default value is retrieved from the view we created.

Then, with the "Custom Code" section offered by Toolset, I've added the following hook:
=> hidden link

add_action('cred_save_data','func_connect_child_posts',10,2);
function func_connect_child_posts($post_id,$form_data) {
    if ($form_data['id']==478) {
            
        toolset_connect_posts('employer-job',$_POST['@employer-job_parent'], $post_id);
    }
}

Now, when I loggedin as employer1 user and submit the form the employer is automatically connected.

#2168835

Dear Minesh,

That's brilliant, it works perfectly! Thank you for your time on this!

My issue is resolved now.