Skip Navigation

[Résolu] Using an intermediate field in a View template conditional test

This support ticket is created Il y a 5 années et 6 mois. 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 9 réponses, has 2 voix.

Last updated by tony Il y a 5 années et 6 mois.

Assisted by: Nigel.

Auteur
Publications
#1117887

I am not able to make a View template to work with an intermediate table connecting two tables with a many to many relationship and wondered if this is a bug, not expected to work or something I have got wrong.

Table 1 is Calendar Event

Table 2 is Organisation-Venue

The connecting table is organisation-venue_calendar-event Intermediary Posts (organisation-venue_c) which has a field "Event-Organisation-Reason" that is mandatory and can have one of three values: "Venue" "Primary Organisation" "Other".

I have run several tests (see below) and also used the numeric code for event-organisation-reason, as stored in the database.

==========================
==========================
The template used in the View is:

<p>
[wpv-conditional if="( $(wpcf-event-organisation-reason).id(organisation-venue_c) = '' "]
[wpv-post-link]<br />
[types field='event-organisation-reason' item='@organisation-venue_calendar-event.intermediary'][/types]<br />
<br />
[/wpv-conditional]
</p>
--------------------------
Result:

Mickleton Village Hall
Venue

Mickleton Table Tennis Club
Primary Organisation
--------------------------

==========================
[wpv-conditional if="( $(wpcf-event-organisation-reason).id(organisation-venue_c) = 'Venue' )"]

No results
--------------------------

==========================
[wpv-conditional if="( $(wpcf-event-organisation-reason).id(organisation-venue_c) ne 'Venue' )"]

Mickleton Village Hall
Venue

Mickleton Table Tennis Club
Primary Organisation
--------------------------
==========================

It would be very helpful if you could advise whether this conditional is intended to work?

I am aware that you cannot use intermediate field in the record selection criteria and wondered if was the also the case for View templates.

Many thanks
Tony

#1118249

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

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

Hi Tony

One thing I'm missing from your description above is, your View, what is it querying? Which post type?

#1118393

Sorry Nigel

My View is "Event Parent Organisation-Venues"

The content selection is:

Organisation-Venues and
organisation-venue_calendar-event Intermediary Posts

My Query Filter is:
Select posts in a organisation-venue_calendar-event relationship that are a related to the current post in the loop.

If I don't apply the condional I see the correct data. If I add the conditional to only select a subset of the results then I see nothing. I ran debug on the conditional and it is comparing the required value against "" (blank).

Thanks
Tony

#1119028

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

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

Hi Tony

You've added this View to the template for Calendar_Events, right?

I'm slightly puzzled as to why your Content Selection is both the Organisation-Venue *and* the intermediary post type.

It means that your View will be looping over both kinds of posts.

Only those which are the intermediate type of post will have the relationship field available, which can be accessed directly without any qualifying id attribute.

The Organisation-Venue posts in the Loop *would* need the post qualifying with the id attribute.

You are mixing up the two interchangeably, and I suspect your View should only be querying Organisation-Venue posts *or* the intermediate post type, but not both, and how you set up the conditional shortcodes would depend on which.

Can you describe what the objective of this View is?

#1119040

Hi Nigel

OK I will explain what I am trying to do, better.

I have Events that are connected to Organisation-Venues with a many/many relationship.

The intermediate record contains a field to differentiate between an Organisation and a Venue relationship so the Event data (1 event) may look like:

Table Tennis on 1st November
> Mickleton Village Hall (Venue)
> Mickleton Table Tennis Club (Organisation)

I have set up a View that now looks only at Events (the intermediate record has been removed from content selection)

The View selects the table tennis Event.

I then adjust the view template to filter and display just the Organisation record details:

=====
[wpv-conditional if="( $(wpcf-event-organisation-reason).id(organisation-venue_c) = '1' )"]
[wpv-post-link]<br />
[types field='event-organisation-reason' item='@organisation-venue_calendar-event.intermediary'][/types]<br />
[/wpv-conditional]
=====

If I remove the conditional both the Venue and the Organisation are listed for the event.

If I include the conditional, neither Venue nor the Organisation are listed.

Hopefully this is a bit more clear.

Regards
Tony

The intermediate field "wpcf-event-organisation-reason" is a radio select

#1119151

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

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

Hi Tony

This is a many-to-many relationship.

Meaning that an event can have many organisation/venue posts connected to it.

Meaning that to display organisation/venue posts connected to an event (even if there is actually only one), you should create a View to display organisation/venue posts with a post relationship Query Filter to specify the event the organisation/venue posts are connected to.

That should be your starting point.

Update your site to work like that, and if you still have problems using the conditional shortcode with fields of an intermediate post let me know and I'll set up a test site to confirm exactly what is required.

#1119159

Sorry - I sent incorrect details:

======================
I have set up a View that now looks only at Events (the intermediate record has been removed from content selection)

The View selects the table tennis Event.
=======================

The View looks only at Organisation-Venues.

It selects the two Organisation-Venue records.

The template in the View then uses the conditional to filter the required Organisation-Venue record.

So the website is set up as you describe.

I can give you access to my test website so you can see the exact code.

Regards
Tony

#1119791

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

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

Hi Tony

OK, thanks for clarifying.

I tested this locally, and the $(wpcf-field).id(slug) format only works for parent posts, not intermediate posts.

For those you need to use the types shortcode itself for the condition. You effectively need to insert the types shortcode as if you wanted to output the field, then cut and paste it into your wpv-conditional shortcode, so that you end up with something like:

[wpv-conditional if="( '[types field='event-organisation-reason' item='@organisation-venue_calendar-event.intermediary'][/types]' eq 'red' )"]
#1119832

Thanks Nigel

That makes sense - I had thought if the conditional was generated in the standard code generator it was intended to work.

I will have a look at your suggested solution as it seems easy to implement.

Kind regards
Tony

#1119833

My issue is resolved now. Thank you!

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