Skip Navigation

[Resolved] Intermediary Post Type

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 3 replies, has 2 voices.

Last updated by Nigel 7 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#402591
layout-host.jpg
host-program-list.jpg
program-and-host_backend.jpg
program-and-host.jpg

Dear Sir/Madam,

I researched the Toolset support forum but could find the answer to my case.

I have a intermediary Post Type 'program-and-host', it is a child of 'program' and 'host' (see screenshot, program-and-host.jpg and program-and-host_backend.jpg).

I want to show the all program related to the host, so I visit the https://toolset.com/documentation/user-guides/displaying-brother-pages/ , I followed the step but could not able to show the program.

I created "Parent Content - Program" and contain [wpv-view name="host-program-list"], View "host-program-list" to list all Program related to the Host. (see screenshot host-program-list.jpg)

I created a layout to place the "Parent Content - Program" into it with [wpv-post-body id="$parent" view_template="parent-content-program"] (see screenshot layout-host.jpg)

The result is No item found from the Parent Content - Program, may I know what step I did wrong?

Best regards,

Kelvin.

#402710

Nigel
Supporter

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

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

You want to show all the programs related to a host.

The documentation you linked to about displaying brother posts is not what you need. Do not confuse the relationships between post types and between the posts themselves.

When we talk of brother posts in that document, we are referring to individual posts that share the same parent post. Say you have 3 parent posts, parentA, parentB, and parentC, and each of these posts has 3 child posts (childA1, childA2, childA3, and childB1, childB2, childB3 etc.). When we talk about sibling posts we mean that childA2 and childA3 are brothers of childA1.

The documentation you need is on this page:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

So, having created your post type relationships ("program-and-host" as a child post of both "program" and "host") you still need to connect the individual posts.

Then when you want to display posts that relate to a given host you create a View that you will add to wherever you display the host (either a template for a host page or as part of another view which displays hosts).

For this View we want to return our intermediate CPT so select "program-and-host" for what to display.

Now we only want to return the intermediate posts for the current host we are looking at, so for Query Filter add a post relationship filter so that event parent is the post where this view is inserted.

Now for the loop output: you can enter the shortcodes for your content directly here or split them out into a Content Template. The key point is that we don't want the content (e.g. post title) for the current post in the loop (which would be our intermediate object), but from one of our post parents ('program') and we specify which using the id attribute.

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

In your case you will manually edit your shortcodes to add the attribute id="$program" to each of them.

If you follow these steps it should work as required, but let me know if you have further problems.

#402721
Screen Shot 2016-05-30 at 6.05.06 PM.png
program-and-host_backend.jpg

Dear Nigel,

Thanks for your help. I still have question to my case, hope you can instruct me.

>>>> So, having created your post type relationships ("program-and-host" as a child post of both "program" and "host") you still need to connect the individual posts.

Did my setting in screenshot "program-and-host_backend.jpg" correct?

>>>> For this View we want to return our intermediate CPT so select "program-and-host" for what to display.

When I select "program-and-host" as the Content Selection, I cannot select the custom field about the host, actually program-and-host is only the post for making relationship but no custom field info for host.

>>>> Now we only want to return the intermediate posts for the current host we are looking at, so for Query Filter add a post relationship filter so that event parent is the post where this view is inserted.

I can't get the meaning, what should I do here? Could you quote the sample?

>>>> Now for the loop output: you can enter the shortcodes for your content directly here or split them out into a Content Template. The key point is that we don't want the content (e.g. post title) for the current post in the loop (which would be our intermediate object), but from one of our post parents ('program') and we specify which using the id attribute.

As I don't know what I should set in the Query Filter, I leave it empty and I change the loop output as below, it assumes all program title should be showed but why the title of "program-and-host" also showed? (see screenshot Screen Shot 2016-05-30 at 6.05.06 PM.png)

		<wpv-loop>
			[wpv-post-title id="$program"]<br/>
		</wpv-loop>
#402806

Nigel
Supporter

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

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

Screen Shot 2016-05-30 at 15.59.13.png
assign comedian and venue.png

Hi Kelvin

You'll have to forgive me, the language of your site makes it difficult for me to recognise what is being output, and your CPTs of "program" and "host" aren't very meaningful to me, so if you don't mind I'm going to walk you through step by step what I have just done to achieve something similar.

In my example I'm going to have custom post types of Comedians and Venues. These are going to be connected by the intermediate CPT 'gigs', so that I can model something like "Louis C.K. has a gig on June 24 at the London Comedy Club".

"Comedians" and "Venues" will both be parents of my intermediate "gigs", and I will need to create a "gig" post for every appearance of a comedian at a venue on a given date. If a comedian appears at the same venue more than once, I will create separate gigs for each appearance.

So, I define my CPTs of Comedians, Venues, and Gigs, and then I set Gigs to be child posts of both Comedians and Venues.

To make this more realistic, I'm going to add a custom date field to my gigs to record when they occur, so I create a custom post field group and add a date field then assign this group to my gigs CPT.

That's my basic set-up, now I must enter some actual data.

I add some comedians, and I add some venues.

Now I add some actual gigs, setting my custom field date and indicating which Comedian and which Venue are parents of this gig. (Note, I can only add the related comedian and venue after initially saving the gig post. See the attached screenshot.)

I have my data, now I want to display it.

Let's say I when I visit a venue page I want to shows all the comedians performing there.

First, to customise my venue page I create a content template which I assign to the venue CPT single post. I'll come back to this.

Next, I create my view.

- I choose to display posts of type 'gigs'.
- I want to see gigs which belong to the venue we are looking at, so I add a filter to "Select posts that are children of the Post where this View is shown". (This means the loop we are coming from, i.e. the venue page, not the loop we are creating with this view query.)
- I add what I want to output in the loop, using the id attribute to refer to fields of a parent post.

For my simple test I am displaying the comedian's name using [wpv-post-title id="$comedian"] and the date (which is a custom field on the current gig in this loop and so doesn't need the id attribute), so it looks like:

	<wpv-loop>
		<h2>[wpv-post-title id="$comedian]</h2>
		<p>[types field='gig-date' style='text' format='F j, Y'][/types]</p>
	</wpv-loop>

Now to display the View. I go back to my content template for venues and add the shortcode for the view I just created.

If I go to a page for a venue I should now see listed who will be performing when, as per the second screenshot.

Hopefully, if you follow along you will be able to get this working with your own version.

Let me know if you are still having difficulties.

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