Skip Navigation

[Resolved] Unable to list the correct child post type related.

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

Problem:
How to display fields from a parent post when showing the child post.

Solution:
Manually edit the shortcodes being used to display content from the parent post to add id="$parent-slug", i.e. the slug of the parent custom post type, which tells Views to use the parent rather than current post as the source.

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by erikE-3 7 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#404112
related-post-types.png
related-post-type.png

I am trying to show the related contact person data (CPT called Contact Person) on another CPT page named Solution (but I call it Product page in my attached image).
I'm stuck here now. I follow your guidance to set up related child post types but just don't get it.
I create the loop in the view and change my content template to show the correct fields, but all I see is the same contact person even if I have selected another on the specific "parent" post type.

Please see my attached image on what I'm trying to accomplish.

Also. How can I add more connections to other pages from the same Contact person?
See image where I manage to select ONE solution from the list. But I want that person to be responsible for more than one Solution page.

Perhaps I've got it all wrong setup in my mind?

My post type called *Contact persons* should be connected to one post type page that I have set up (called Job position).

Thanks!

#404168

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Erik

Let's work on your data structure before we worry about how to set Views up to display it.

From your second point, you can have one-to-many relationships—one parent can have many children—but you cannot have many-to-one relationships in the sense of one child having many parents. From your related-post-type screenshot, you cannot assign more than one parent to a child post.

So, you have a post type "Solution", and another post type "Contact Person".

One Contact Person can be linked to multiple Solutions, but a Solution only ever has one Contact Person, is that correct?

If so, then Contact Person is your parent, and Solution is your child. When you publish a solution you will set the parent Contact Person.

Now, displaying your results, can you clarify what you are aiming for? From your chart it looks like you want to display details of the Contact Person on the single Solution page. From your final line it looks like you want to have a page called "Job position" which shows a list of Contact Persons and the Solutions they are linked to, is that correct?

If I have that right let me know and I can help you set up your Views.

#405105

Hi Nigel,

1.
Nigel:"So, you have a post type "Solution", and another post type "Contact Person".
One Contact Person can be linked to multiple Solutions, but a Solution only ever has one Contact Person, is that correct?"

Me: Yes That's correct!

2.
Nigel: "If so, then Contact Person is your parent, and Solution is your child. When you publish a solution you will set the parent Contact Person."

Me: Yes. I've set it up like this and can select a person for each Solution. Same goes for another relateion where I have a CPT called Job position. I want the same contact folks to be available here (they should be visible on each job position page as contact person for a specific job position).

3.
Nigel: "Now, displaying your results, can you clarify what you are aiming for? From your chart it looks like you want to display details of the Contact Person on the single Solution page. From your final line it looks like you want to have a page called "Job position" which shows a list of Contact Persons and the Solutions they are linked to, is that correct?"

Me: Yes I want to display the correct contact person (and his post fields) for each solution page.
Same goes for a Job position. Same setup - I want to show the correct contact person for each job position.

So from what I understand CPT "Contacts" will be parent to CPT "solutions" and "Job positions"?

Now I need to get help with the views for this.
Thanks

#405156

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Good, so with the data set up how you need, you now want to be able to display fields from a parent post when showing the child post.

That is, you want to show fields from the parent Contact when showing a Solution, or a Job Position.

If the slug of your Contacts CPT is 'contact' then the trick is to manually add id="$contact" to shortcodes where you want to refer to the parent contact, e.g. when displaying a Job Position if the name of the contact is stored in the title then you would output it via

[wpv-post-title id="$contact"]

The documentation is here:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

#405774

Hi Nigel,
Well that's exactly what I've been doing - added the id for my post type (contact-person).
BUT I thought I needed to create a view with a loop first (!). The result: Showing the last added person on ALL Job positions :-/

Just added the fields in a visual editor field now and it works fine!
Thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.