Skip Navigation

[Resolved] Problem when displaying multiple post types in a view.

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

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
- 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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by kostasT 2 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2288703

Hi

I work on 3 custom post types: 1) Scientific Products, 2) Accessories and 3 Spare Parts & Consumables. I created 2 many to many relationships: 1) Scientific Products and Accessories and 2) Scientific Products Spare Parts & Consumables.

In the Scientific Product template, I want to display the related Spare Parts & Consumables and Accessories all together. So, I setup a view and enabled the multiple post types in a view. I add a filter to show only the post with a relationship with the current post. I use the Kadence infobox to present each related product. However, I can select from only one custom post type. The post title is displayed for both Accessories and Spare Parts & Consumables, but the image only from one of them. Please see the section named "Related Products".

By checking the support forum, I found a workaround. You can check the section "All related products" where I use the Toolset's Heading and Image blocks. I added 2 image blocks, one per custom connected type. Although it works, it requires a lot off time to create a similar aesthetic view as the Kadence Infobox. Do you have any suggestions on how to use the infobox to display multiple post types in a view? Should I add conditionals? Have in your mind that, eventually, I will have many connected post types.

You can check it here:
hidden link

You already have an account on the website because I have another support ticket open.

Thank you.

#2289243

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

The challenge here is that your website is using different custom fields for images, in each post type. Although the field name "Image" is the same, the actual field slug is "spc-image" in the 'Spare Parts & Consumables' post type and "accessory-image" in the 'Accessories' post type.

While adding separate "Info Box" blocks for each post type inside the conditional block that checks for the post type can work, it can be cumbersome to maintain in the long run.
( due to repetition and an increasing number of connected post types )

A better alternative can be to use the same custom fields across the post types for the fields which you'll need in all of them. For instance, currently in the two custom field groups 'Field Group for Spare Parts & Consumables' and 'Field Group for Accessories,' you have two common purpose fields for image and short description, but with different slugs. You can include a common custom field group called something like 'Field Group for common fields' and set it to be attached to both 'Spare Parts & Consumables' and 'Accessories' post types. This way you won't have to set different "Info Box" blocks for each post type because the dynamic source custom fields would be the same.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2289841

Fine! It works now!

I have another related question. Is it possible to use the conditional block in order to check if there is any related product? And in that case, I will display the related products section. Otherwise, I will not display anything.

Thank you.

#2291881

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that it works.

To hide the related products section, when a view contains no results, you can follow these steps:

1. In the related products 'Section' block, include a special class 'related-section-container'.
( screenshot: hidden link )

2. Next, in the view's 'View Loop' block, include some custom CSS code in the 'No Items Found Text' field:
( screenshot: hidden link )


<style> .related-section-container {display: none;} </style>

As a result, whenever the view will have no results, the custom CSS code will hide the entire section.

#2292675

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.