Skip Navigation

[Resolved] Conditional by no relationship with CPT

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

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 5 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1233635

I need to display a text if the post in view loop don’t have relationship with a specific CPT.
How can i set conditional checking relationship?

#1233867

Hi there,

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

For this conditional comparison, based on whether a post-relationship exists or not, you can follow these steps:

1. Please create a new view, which shows only those posts from the specific CPT, that you'd like to use for this condition.

2. In the "Query Filter" section add a post relationship filter, which brings in only those posts which are in relationship with "The current post in the loop".
( example screenshot: hidden link )

3. In the "Loop Editor" section, you'll just need the count of returned posts ( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-155378 ), if any are found, and 0 in case there are none:


[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>[wpv-found-count]</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]0[/wpv-no-items-found]
[wpv-layout-end]

Note: Please also check the option for the "Disable the wrapping DIV around the View", at the bottom.

4. In your actual view, you can use this newly created view in conditional blocks like this:
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/ )


[wpv-conditional if="( '[wpv-view name="slug-of-the-new-view"]' eq '0' )"]
No items found
[/wpv-conditional]

[wpv-conditional if="( '[wpv-view name="slug-of-the-new-view"]' gt '0' )"]
Some items found
[/wpv-conditional]

Please replace "slug-of-the-new-view" with the actual slug of your new view.

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

regards,
Waqar