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?
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