Skip Navigation

[Cerrado] Views and intermediary custom types

This support ticket is created hace 10 años, 7 meses. 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 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

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

This topic contains 10 respuestas, has 3 mensajes.

Last updated by Simon hace 10 años, 7 meses.

Assigned support staff: Caridad.

Autor
Mensajes
#12775

Hi there - I have used the approach outlined here:

https://toolset.com/faq/how-do-i-associate-one-child-with-several-parents-of-the-same-type/

to create various many-to-many relationships between different post types. Now I need to work out how to pull the content through in to Views to be included in Content Templates.

I have hidden the intermediary custom types that I created. As far as I can tell, the normal method for displaying the contents of child content (https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/) is not applicable here as what I want to show is not a child - it's content that is the parent of a child post of the current post.

Hope that makes sense! Thanks in advance...

#12884

Hi Simon,

You still need to use the same method as here - https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

You then use a Content Template to display your child posts. In the Content Template you can use [wpv-post-title id="$XXXXX"] (where XXXXX is the name of the parent).

I hope that makes sense.

Best regards,
Bruce.

#12891

Hi Bruce,

I am still confused :/

Let me describe my scenario. I have a post type called 'Event'. I have another post type called 'Venue'. On the Content Template for Event I want to display which venue the event takes place in. On the Venue Content Template I want to show all the events that take place in that Venue.

Because multiple events can take place in each venue, this is a many-to-many relationship, so as per https://toolset.com/faq/how-do-i-associate-one-child-with-several-parents-of-the-same-type/ I have created intermediary custom posts. The post type is called 'Event to Venue' and is hidden to avoid confusion. It is the child of both Event and Venue.

I understand the principle of how to display the contents of child posts in a Content Template using a View. I have created a simple View called Venues - but when I set a filter on that View to say "only show results that are the child of the current Post", no results are returned, because the Venue is NOT technically a child of the Event, it's connected via an intermediary post.

Thanks!

#12892

Hi Simon,

Is your View returning 'Event to Venue' custom post types? Then in your View you can output the parent 'Event' using the id="$event" on your shortcodes.

eg.
[wpv-post-body view_template="my-event-template" id="$event"]

I hope this helps,

Best regards,
Bruce.

#12899

Hi Bruce

> Is your View returning 'Event to Venue' custom post types?

Yes - but I am really really sorry, I am still confused. Do you mean I should use the shortcode example you gave in Content Template where I am loading the View? Or in the meta-HTML of the view itself?

This is all a bit of a head trip - having come to Views fresh, I really need it for this advanced relational work for our website to behave as it should...

Thanks, Simon

#12907

Dear Simon,

I am not certain you need a many-to-many relationship here. And its generally easier to avoid it. So let me first clarify if you really need it. You said:

"Because multiple events can take place in each venue, this is a many-to-many relationship"

This looks like parent / child relation where Venue is the parent and Events are childs. Unless an event can also take place in several venues. Is this so?

Regards,
Caridad

#12909

Hi Caridad,

Maybe Events / Venues is not the best example. Events and Speakers is a better one - an event can have multiple speakers, and each speaker could speak at more than one event. No way to avoid many-to-many in that context.

So, I have the following set up:
- Custom data type Speakers (slug: speakers)
- Custom data type Events (slug: event)
- Custom data type Event to Speaker (slug: eventtospeaker), which is a child of both Speakers and Events

The relationships are set up and working as per https://toolset.com/faq/how-do-i-associate-one-child-with-several-parents-of-the-same-type/

So, I have created a Content Template called 'Event Detail' - this displays various event fields, and also needs to list all the Speakers who are associated with the Event. That's where I am struggling and would appreciate help.

Thanks, Simon

#12913

Dear Simon,

To display speakers in an event, load the ‘eventtospeakers’ of an event and then, load the speaker of an eventtospeaker.

So, create a new view that lists all speakers for the eventtospeaker set by post where this View is inserted. Add fields for the speaker here.

Next, in your event view template, add this shortcode:

[wpv-view name="name of view created" id="$eventtospeaker"]

Having said all this, I havent actually tested it. Please try it and let me know how it goes.

Regards,
Caridad

#12914

Hiya, I think I am getting some of the way there. Jumping in to your step-by-step, you say:

> To display speakers in an event, load the ‘eventtospeakers’ of an event and then, load the speaker of an eventtospeaker.

Should this View _just_ load Event to Speaker? Here is what the View looks like as I have done it:

Event to Speaker, ordered by post date, descending
Select related posts that are a child of the post where this View is inserted

> So, create a new view that lists all speakers for the eventtospeaker set by post where this View is inserted. Add fields for the speaker here.

You say 'Add fields for the speaker here' - so I add a couple of fields associated with the Speaker type. I add:
- Basic - title (which will give the system-generated title of the Event to Speaker linking post)
- Speaker details (artist website field) (several of the linked speaker records have data in this URL field)

At this point, if I just load the new view (called 'test') in to my View template, using [wpv-view name="test"], it spits out the post names of my linking posts (in the form post new_1042282573 post new_804935745 post new_2122348972), but no other fields. It IS displaying the correct IDs, though, so that's a good start.

> Next, in your event view template, add this shortcode:
> [wpv-view name="name of view created" id="$eventtospeaker"]

So now I add the extra paremeter to the shortcode - [wpv-view name="test" id="$eventtospeaker"] - and all my post IDs disappear 🙁

The problem here seems to be making the jump from the linking post ID to the speaker details i.e. the "load the speaker of an eventtospeaker" bit...

Thanks for your patience!

Simon

#12923

Dear Simon,

Sorry about my previous post, some things were incorrect. I have followed the tutorial and I have a better idea of how it works now. Let me explain from the start:

1) Create a view template to list the parent speaker:
[wpv-post-title id="$speaker"]

2) Then create a view for eventtospeakers, and add the previous view template as a field. This view needs to filter posts that are "child of the post where this View is inserted".

3) Finally, insert the view created in step 2 in your event view template.

I hope its clear now.

Regards,
Caridad

#12924

It worked 😀

(once I spotted that the slug is speakers, not speaker)

Thanks for all your help, now I can get busy with my relational data!

El debate ‘[Cerrado] Views and intermediary custom types’ está cerrado y no admite más respuestas.