Skip Navigation

[Resolved] Conditionally display content based on the existence of a post relationship

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

Last updated by saulB-3 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2183641

Hi there,

I'm making a portfolio website with Clients and Projects custom post types, and there is a one-to-many relationship between them. On each Client page, I would like to display a subheading ("Projects") and bulleted list of the titles of each Project post if the Client post is connected to one or more Projects. I know I need to use a conditional block, but I'm not sure how to test for "more than 1 connected post." And to be clear, I understand how to display the connected posts, I *don't* understand how to conditionally display the subheading.

Thanks!

Saul

#2184171

Shane
Supporter

Languages: English (English )

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

Hi Saul,

Thank you for getting in touch. The best way to achieve this is to use the classic view setup to display your post relationship information.

The classic view will allow you to add your title inside the view itself but will only display if the view has found any items.

To do this with the classic view it must first be enabled.

Go to Toolset -> Settings and scroll to editing experience and enable the 3rd option. Once you've done this refresh the page and you should now see Toolset -> Views.

On the Toolset -> Views page add a new view and then select your child post type. Under the Query filter section add a query filter for Post Relationship and set the relationship.

Now in the loop output section you should see the Loop Wizard button. Use this to add your content to the view loop. It should be noted that this will create a content template for the view using the Block editor so you will be able to add your information using the gutenburg editor as you're current accustomed to.

Back to the Loop Output section you will see a shortcode called [wpv-items-found]. Under this shortcode you can add your heading and it will only appear when the view has found any items.

Please let me know if this helps.
Thanks,
Shane

#2184203

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.