Skip Navigation

[Resolved] Want to display the parent of child in a view (May have set it up inefficiently)

This support ticket is created 7 years, 5 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
- 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)

This topic contains 11 replies, has 2 voices.

Last updated by owenC 7 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#520262

I am trying to:
Display the related parent 'Style of Beer' of the child 'Beers' in a View for each single 'Beer' post.

My website is set up as $parent = Breweries
$parent = Style of Beer
$child (of both $parents) = Beers

I set it up like this because both a Brewery and a style can have many beers. Later I can then set up Views for beers by Brewery and by Style. I'm not sure if this was the correct or most efficient way to do this, though.

I visited this URL:
https://toolset.com/forums/topic/displaying-parent-fields-from-child-view/
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

I ended up getting confused about what I needed to do and after the excellent help Christian gave me on a separate issue, it seemed a good idea to ask for assistance again.

Thanks

#520304

Shane
Supporter

Languages: English (English )

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

Hi Owen,

Thank you for contacting our support forum.

Could you let me know what you have so far and what from the parent you will like to display on the child?

Usually you can display the parent information by passing the slug of the parent in the format $parent-slug as an ID parameter in our shortcode.

Thanks,
Shane

#520561

HI Shane

This is the code I have so far:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
	// I want to put the title of parent style here that relates to the beer e.g. 'All In Jim' is an American Pale Ale.
[types field='abv'][/types]
[types field='availability'][/types]
[types field='notes-commercial-description'][/types]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Then I would add that View to the single Beer page.

#520710

Shane
Supporter

Languages: English (English )

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

Hi Owen,

Thank you for sharing the code.

Just to confirm you want to display the style of beer using this code correct?

If so could you let me know the slug of the style of beer CPT.

Thanks,
Shane

#520732

Hi Shane, the slug is: style

#520736

Shane
Supporter

Languages: English (English )

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

Hi Owen,

The parent Style is stored as the Title of the parent or as a taxonomy.

In order to display the correct information I need to know exactly because all you need to do is to use the id = '$style' attribute in any shortcode and it will always display the parent information.

Thanks,
Shane

#520742

Hi Shane,

Its stored as the title of the parent.

Thanks

#520754

Shane
Supporter

Languages: English (English )

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

Hi Owen,

Then you will need to do this.

[wpv-post-title id='$style']

Just add that to any of your Beers and it should display the title of your Parent Post.

Thanks,
Shane

#521434

Hi Shane

I think I must be doing something wrong. The View doesn't appear to be showing the correct information. This is the code I have:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
      <strong>Style:</strong> [wpv-post-title id='$style']<br />
      <strong>Alcohol by Volume (ABV):</strong> [types field='abv'][/types]<br />
      <strong>Availability:</strong> [types field='availability'][/types]<br />
      <strong>Commerical Description:</strong>[types field='notes-commercial-description'][/types]<br />
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

When I insert this View into my Single Beer layout, it is showing information for a completely different beer. I need it to display the current beer.

hidden link

You can see in the above link it says 'English Pale Ale' and '3.7%' but this is from a different beer.

Thanks
Colin

#521613

Shane
Supporter

Languages: English (English )

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

Hi Owen,

Would you mind if I took a look at this through the backend ?

I should be able to diagnose the exact issue once i'm logged in.

The private fields will be enabled for your next response.

Thanks,
Shane

#521664

Shane
Supporter

Languages: English (English )

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

Hi Owen,

Actually don't use a view for this.

You can use a simple text editor and add this to it and it should work just fine.

<p><strong>Style:</strong> [wpv-post-title id='$style']<br />
<strong>Alcohol by Volume (ABV):</strong> [types field='abv'][/types]<br />
<strong>Availability:</strong> [types field='availability'][/types]<br />
<strong>Commerical Description:</strong>[types field='notes-commercial-description'][/types]</p>

Please let me know if this helps.
Thanks,
Shane

#521955

Hi Shane

That works fine, thank you.

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