Skip Navigation

[Resolved] Conditional Display For One-Many Relationship in parent Post

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want to hide media slider if there is no image which is child of property post type.

Solution:

It needs a child post view, for example:

https://toolset.com/forums/topic/conditional-display-for-one-many-relationship-in-parent-post/#post-1880021

Relevant Documentation:

https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

0% of people find this useful.

This support ticket is created 4 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Rahul Jat 4 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1879947

Tell us what you are trying to do?
=> I want to hide media slider if there is no image which is child of property post type.

Is there any documentation that you are following?
==> I follwed this suggestion: https://toolset.com/forums/topic/conditional-display-for-one-many-relationship-in-content-template/
But it displays first image then it hides whole slider.

Is there a similar example that we can see?
==> https://toolset.com/forums/topic/conditional-display-for-one-many-relationship-in-content-template/

What is the link to your site?
You can check it here: hidden link

Please suggest how can I solve this issue. I have used this shortcode:
[wpv-conditional if="( '[wpv-post-id item='@property-media.child']' ne '' )"]

Display slider

[/wpv-conditional]

It worked but only displays first slider image and then it goes blank.

Property ==> Parent post type
Property media ==> child post type

One property will have many medias(one-to-many relationship)

Thanks,

#1880021

Hello,

In your case, it needs a child post view, for example:
In the single "Property" post, display a post view:
- Query "child post type" posts,
- Filter by:
a) Relationship between "Property" and "Property media"
https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items
b) Your custom image field isn't empty:
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/
- In view's loop, display your sliders

#1880127

Hello,

Thanks for your reply!

Actually I have already created post view and displayed media images in slider for that property but the issue is that it is displaying no-items text if there is no-medias with current property and I want to hide that text.

That's why I have created conditional statement for slider but it is not working. Can you please take a look here:

Property page with no-media : hidden link
Property page with media: hidden link

Thanks,

#1880153
view-loop.JPG

You can simply remove that text, for example, edit the page you mentioned above, find and select view block, find and select "View Loop" block, remove the text from option "No Items Found Text", see my screenshot:
hidden link

#1880309

My issue is resolved now. Thank you!