Skip Navigation

[Resolved] Hierarchy of same post type

This support ticket is created 6 years, 1 month 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 13 replies, has 3 voices.

Last updated by geoffD 6 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1117313

Hello

I am trying to connect a CPT with other posts of the same type using the WordPress built in parent/child post hierarchy.

So far example my CTP is 'PERSON' and I want to associate a single 'PERSON' with many other 'PEOPLE' so one person could have many friends.

I'm just not sure using CRED forms how to implement this on the front end...

Hope that makes sense

Best wishes

Geoff

#1117574

Well, you cannot do a Post Relationship within the same Post Type, with Toolset.
What you can do is use the native WordPress Post's Hierarchy on Custom posts created by Toolset, I understand you mean this.

In that case, you will:
- enable support for hierarchy in the Post Type Edit Screen (Toolset > Post Types > your_post_type > Edit > Sections to display > Page Attributes, and Toolset > Post Types > your_post_type > Edit > Options > hierarchical)
- that should now allow you to connect many posts of that type to (one) post of the same kind

In Toolset Forms, you can now create a Form to add new Posts of that kind, and it will automatically (if autogenerated) show the selector to pick the desired parent Post, as it is in the backend as well.

The shortcode doing this in the Form will look like:

[cred_field field="post_parent" class="form-control" output="bootstrap" select_text="--- not set ---"]
#1117597

Hi Beda...thanks for getting back to me so quickly...especially at weekend!

Yes that's exactly what I want to do however slightly different to the way you propose...

I want to be on the child page with a list of possible parents..you would then click on a link next to one of the parents to go to the form to add them as the child's parent... would I just use - cred_field field="post_child" instead in the form?

Presumably the child ID gets passed from the link to the red form?

Many thanks

Geoff

#1117598

You can do that only by linking to a Form that edits the actual child
Next to each parent you can simply add a Link to the Form and pass the Post ID to be set as that parent in the URL attribute which you can pass in the ShortCode of the form, example:
[cred_field field='post_parent' class='form-control' output='bootstrap' select_text='--- not set ---' value='default' urlparam='parent_to_set']
I added a ScreenShot about where to set that.

Later, in the Front End, you link to this Edit Form and append the URL parameter parent_to_set (it must pass the Parent ID)
That will make it so the form already has the right parent selected, you could even hide it so it's not editable and the user simply clicks "connect" (submit button)

#1117605
parent-child.jpg

Hi Beda

Thanks for your help so far...

I understand the concept of what you're saying but am still unsure how I :

a) Make a link to edit the current person
b) Set the parent to child from the person edit form..

I have attached a diagram to demonstrate what I want to do...if you could use this structure...

I'm no expert so need step by step guidance please.

I couldn't find the screenshot by the way...

Best wishes

Geoff

#1117616

The link to edit the current person is made with Toolset when you open the Toolset Forms GUI that is present in any Editor you can insert Edit Links that lead to the Toolset form.
That form needs to be in a Content Template first
It's shown here, sorry for not having linked it previously:
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-editing/

You can then copy the link that ShortCode creates from the HTML it generates, which results in something like:

<em><u>hidden link</u></em>

That means to craft your links that lead to that Form, and automatically pass the chosen Post as the parent within the same type, you craft this link:

<em><u>hidden link</u></em>

3 here is the ID of the parent post I want to be connected, 29 the ID of the Content Template where the form is.

To have all this dynamic, you will create the above Links with ShortCodes, like this:

<a href="[wpv-bloginfo show='url']/the-person-post-type/[wpv-post-slug]/?content-template-id=29&parent_to_set=3">Assign Post 3 to the current post as parent</a>

This, of course, assumes that you set the Forms' shortcode as I illustrated here.
https://toolset.com/forums/topic/hierarchy-of-same-post-type/#post-1117598

You need to create the list of potential parents either manually, or use a View for that, which you then insert in every single post (or a template applying to them)

#1117675

Hi Beda

Ok I'm struggling!... I understand the bespoke links you made above but they son't dynamically choose the parent ID of the parent selected (I don't think e.g. parent_to_set=3 (where 3 could be 122, 200002 or whatever the post ID)

So far I have got the page of the CHILD and have created a list on this page of potential PARENTS. Next to each potential PARENT I have created a link that takes you to the edit page of the CHILD - Here's the link:
[toolset-edit-post-link layout_slug="people-add-guardian" id="$current_page"]Choose Parent[/toolset-edit-post-link]

When the link is clicked from any of the potential PARENTS it takes you to the edit page of the CHILD. I need to send the ID of the selected PARENT in the list to the CHILD edit form...but am really lost as to what to do..

Your help is much appreciated...

Best wishes

Geoff

#1118198

Minesh
Supporter

Languages: English (English )

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

Well - could you please tell me what exactly you are trying to achieve.

As Beda said - if you want to see parent ID in URL param - you need to contract the links as given under:

<a href="[wpv-bloginfo show='url']/the-person-post-type/[wpv-post-slug]/?content-template-id=29&parent_to_set=3">Assign Post 3 to the current post as parent</a>

Do you want to save parent ID to child post - automatically once you save the form?

Please share problem URL and access details with step information what exactly you want to achieve, that will help me to guide you in the right direction.

I have set the next reply to private which means only you and I have access to it.

#1118226
parent-child.jpg

Hi Minesh

Do you want to save parent ID to child post - automatically once you save the form? - Yes please

So your link below:
Assign Post 3 to the current post as parent
It says 'parent to set=3' I need to set this dynamically....I have re-attached the image I made trying to demonstrate the problem I'm having....The user follows 3 steps:

1. The user is on a CPT page 'CHILD' and on that page is a list of potential PARENTS, the user will select a link next to ONE of the parents which will take them to:
2. An edit page of the CHILD from the previous page but on this page there is a hidden field that sets up the PARENT/CHILD relationship between the CHILD and the PARENT selected
3. The user clicks submit to send the form.

I hope this makes sense...I shall look forwards to hearing from you

Best wishes

Geoff

#1118254

Minesh
Supporter

Languages: English (English )

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

Ok - could you please share problem URL and access details so I can see how you configure your link.

*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1118909

Minesh
Supporter

Languages: English (English )

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

Could you please check now.

I've added following code link to your view that displays potential parents:

<a href="[wpv-bloginfo show='url']/index.php/[wpv-post-type]/[wpv-post-slug id="$current_page"]?layout_id=2573&parent_id=[wpv-post-id]">Choose New Parent</a>

With your page now you will see another link "Choose New Parent" link besides titlte "Potential Parent 3"- when you will click on that - it will redirect you to the form and to the form I've added following field:

[cred_field field="post_parent" class="form-control" output="bootstrap" value="[wpv-search-term param='parent_id']"]

The form field will assign the parent value from URL param "parent_id" which we passed from view.
=> hidden link

now - when you save the form - it should work. Could you please confirm, you want this solution or I misunderstood something here.

#1119153

Hi Minesh

That's perfect thank you...just what I need...

The second part of my problem is to create a new PARENT rather than an existing one... so on the page

hidden link

...you would select a CHILD to give a parent to by clicking 'Choose Parent'.. That would then take you to the CHILD page with the list of potential PARENTS but underneath is now a button saying 'Create NEW PARENT' ..this takes you to the page:
hidden link

Where there is a form to create a new PERSON so I need this person to be the CHILD's PARENT..

Thank you for your help

Regards

Geoff

New threads created by Minesh and linked to this one are listed below:

https://toolset.com/forums/topic/split-hierarchy-of-same-post-type-create-new-parent/

#1119925

Minesh
Supporter

Languages: English (English )

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

Glad to know that solution I shared works for you and help you to resolve your original issue.

Could you please resolve this ticket and we will continue with your another problem to connect parent with child with following brand new ticket.
=> https://toolset.com/forums/topic/split-hierarchy-of-same-post-type-create-new-parent/#post-1119923

#1119949

My issue is resolved now. Thank you!