Skip Navigation

[Resolved] Display Child Post Field in Parent Post Views

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

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+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#627677

Hi

I have 2 Post Types
Parent -> Hotels --- Custom Field -> Country
Child of Hotel -> Rooms

I have created views for Rooms to display all the rooms.
Select posts that are children of the Post with ID set by the shortcode attribute wpvprchildof.
eg. [wpv-view name="view-name" wpvprchildof="123"]

Loop Output Editor

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%">
<tbody class="wpv-loop js-wpv-loop">
<wpv-loop>
<tr>
[wpv-post-body view_template="Loop item in Search Rooms"]
</tr>
</wpv-loop>
</tbody>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

Templates for this View
<td>[wpv-post-link]</td>

Parent View->
Query Filter ->
[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
<label>[wpml-string context="wpv-views"]Country[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-country" url_param="wpv-wpcf-country"]
</div>
[/wpv-filter-controls]
[wpv-filter-end]

Loop Output Editor

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%">
<tbody>
<wpv-loop>
<tr><td>[wpv-view name="search-rooms" child_of="992"]</td></tr>
</wpv-loop>
</tbody>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

Template ->
[wpv-post-link]

Somehow its not working when select the country-> it shows all the hotels

I want to display
Room|Hotel|Country

I looked at this ticket but somehow not working

https://toolset.com/forums/topic/parametric-search-filtering-by-parent-types-field/
https://toolset.com/forums/topic/how-to-filter-childs-post-depending-on-a-parent-field-value/

#627798

Nigel
Supporter

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

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

Hi there

I'm not sure what you are trying to do: specifically why you are hard-coding the hotel using a shortcode attribute.

Let's put aside what you have done so far for the moment.

I understand you have a parent post type "hotel" with a field "country" and a child post type "rooms", i.e. rooms belong to a particular hotel.

Can you describe what you are trying to display?

The typical scenario would be that you want a search form where users select a country and the list updates to show hotels in that country, while showing the rooms belonging to each hotel.

You clearly want something different. If you can explain what, I can help you set it up.

#627910

Thanks Nigel. I guessed it absolutely right. I wanted to give as much as details but ended up complicating things.

I understand you have a parent post type "hotel" with a field "country" and a child post type "rooms", i.e. rooms belong to a particular hotel.
The typical scenario would be that you want a search form where users select a country and the list updates to show hotels in that country, while showing the rooms belonging to each hotel. I know this should be very simply task with Views but I just couldn't get it working.

#628378

Nigel
Supporter

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

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

hotels.gif
Screen Shot 2018-03-26 at 15.30.15.png

OK, so for this on my local site I have set up a CPT for Hotels and a child post type of Rooms, and the Hotel post type has a custom select field for the country, and I created a few sample posts.

Then I create a new View, choosing the option for a custom search View.

The View will display Hotel posts,

In the Filter Editor I insert a filter for the country custom field.

In the Loop Output section for now I just output the post title as a link.

If I add this View to a page and visit the page I will be able to search my hotels by country.

Now I create a second View.

This View will be a simple View that displays all results and which queries Rooms.

I add a Query Filter to only show Rooms that are children of the current post in the Loop (see screenshot).

I then add some fields to display in the Loop Output section.

Now I return to my original View of Hotels, and edit the Loop Output section.

Using the Fields and Views button I insert my second View within the wpv-loop tags where I want the info from the rooms to appear.

You can see the (crude) results in the screen recording.