Skip Navigation

[Resolved] Display child view based on post reference field

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Shane 6 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1128966

Ok, so I got help grouping a view by a Post Reference field, at https://toolset.com/forums/topic/grouping-by-post-reference-field-does-not-work/#post-1128377.

Now, for each item in the view I want to display another view that lists one or more items based on another post reference field.

Here's what I have to try this out:

1) The main view "Test", that lists all items in the "race" CPT. It currently displays the post titles of the Post Reference field "race_event", which connects to the "event" CPT. It also groups the loop items by those event titles with the code in https://toolset.com/forums/topic/grouping-by-post-reference-field-does-not-work/#post-1128377.

2) Another post reference field in the "race" CPT is "Bana", that connects to the "course" CPT. In the "course" CPT there is a field called "course_distance". Now for each item in the loop in the view "Test" I want to display all the "course_distance" fields that has the same "race_event" from #1.

Example:
a) There are 4 posts in the "race" CPT that are connected to the same event via the "race_event" Post Reference field. In this case the event is called "Tjörnarparen". They only display once, as the view is grouped by the race_event field.
b) Each of those 4 posts are connected to different courses via the "race_course" Post Reference field. In this case the course_distance fields of those connected courses are 50K, 50M, 100K and 100M.
c) In the one list item "Tjörnarparen" I want to display all those four distances.

I have created a view called "Visa alla distanser". But I am not sure how to call that view from the "Test" view, in order for it to display the items for the current list item. With the current code, all the distances of all the posts in the the "course" CPT are listed for each list item in the view "Test". How can I list only those related to the races that share the same event?

In the view "Visa alla distanser" I tried the item='@race_course.parent' parameter, but that displayed nothing. I suppose it may again have to do with the ID vs title of the post reference field?

#1129338

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johnny,

Thank you for contacting our support forum.

Could you send me a link to the page where I can have a look at what has been done so far?

Thanks,
Shane

#1129351

The output is at hidden link

The main view is at hidden link

The view for all distances that I'm trying to include in the main view is at hidden link

#1130029

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johnny,

So what from your post I gather that you want to display a custom field from one of the referenced post field on the Posts correct?

#1130547
upcomingraces-wantedoutput.png
upcomingraces-grouped.png
upcomingraces-notgrouped.png

Well, let me try to explain again.

  • 1) First I have the following code:
    <li>[types field='race_startdate' style='text' format='j F, Y'][/types] - [wpv-post-title id="[wpv-post-field name='wpcf-race_event']"] 
      <span class="distance badge">[types field='course_distance' format='FIELD_VALUE' item='@race_course.parent'][/types][types field='course_time' format='FIELD_VALUE' item='@race_course.parent'][/types] [types field='course_unit' item='@race_course.parent'][/types]
      </span>
    </li>
    

    That displays a list of all races, as shown in attached image, upcomingraces-notgrouped.png.

  • 2) Now I want to group races with the same event name and the same date. I wrap the
    <li>

    tag in the following shortcode:

    [group-title condition="title" value="[wpv-post-field name='wpcf-race_event'] [types field='race_startdate' style='text' format='j F, Y'][/types]"]

    That groups the races fine and all, but the distances from the course_distance field from the Courses CPT as related via the Post Reference field no longer displays anything. Probably because its values are not sent to the function for the [group-title] shortcode. See attached "upcomingraces-grouped.png"

  • 3) In #1 you can see there were multiple races, each with their own distance, that all have the event name "Tjörnarparen" and the date "8 december, 2018". When all those four races are grouped together in #2 I want to display all those four distances in the now one list item, as in the attached image "upcomingraces-wantedoutput.png". There you can see all the four distances of the four races witht he event name "Tjörnarparen" on 8 december, 2018.
  • 4) As you can see I output both the field "course_distance" and the field "course_time", which may give the wrong output, such as the double "100100". I want to wrap those in a conditional, based on the value in the field "wpcf-course_timeordistance" from the CPT "Courses" that is related via the Post Reference field "race_course". What should be the code for that? I have tried
    [wpv-conditional if="( $(wpcf-course_timeordistance) eq 'Distans' )"]

    , but need to add the ID for the post reference field somehow, in order to get the value from the referenced CPT.

  • I hope this better explains what I'm trying to achieve.

    #1130799

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Johnny,

    I took another look at this for you and it is as you say, the field values are not being passed to your custom shortcode. Unfortunately I wouldn't be able to debug this for you as the issue is on the end of the custom shortcode because when not in the shortcode it works fine.

    Why not pass all the values into individual shortcode parameter and format it and then print it out ?

    Please let me know if this helps.
    Thanks,
    Shane

    #1131959

    "Why not pass all the values into individual shortcode parameter and format it and then print it out ?"

    How would I do that? As I need to print possible multiple values for distance for each event title, I would somehow need to loop through all the distances of the courses related to the parent event of the current race. Otherwise only the first distance value will be printed, as the following occurrences of the same event title will not be output due to the [group-title] shortcode.

    That is, how can I use shortcode code to loop through all the Course CPT posts that are children of the same Event CPT post that is the parent of the current Race CPT post?

    #1132197

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Johnny,

    When i say passing the value into the shortcode, i meant doing it like this.
    [group-title condition="title" param_1="[wpv-post-field name='wpcf-race_event'] [types field='race_startdate' style='text' format='j F, Y'][/types]" param_2 = '[shortcode]' param_3='[shortcode]'][/group-title].

    Please try constructing your shortcode to accept the parameter like this .

    Unfortuntely I cannnot provide any debug assistance on this since the issue is not with our shortcodes.

    Thanks,
    Shane