Skip Navigation

[Resolved] Conditional display if view results >0

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

Problem:

Build a conditional display based on wether if the view has results or not.

Solution:

When you edit a post view, you can display the post found count with shortcode [wpv-found-count]
https://wp-types.com/documentation/user-guides/views-shortcodes/#wpv-found-count

In section "Loop Editor", there are two sets of shortcodes:
[wpv-items-found] ... [/wpv-items-found]
[wpv-no-items-found] ... [/wpv-no-items-found]

You can use them to display different results "based on wether if the view has results or not".

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-items-found

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-no-items-found

This support ticket is created 4 years, 9 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by romanB-3 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1576213

Hello,
I wonder how I may count results of a view in order to build a conditional display based on wether if the view has results or not.
Thank you.

#1576549

Hello,

When you edit a post view, you can display the post found count with shortcode [wpv-found-count]
hidden link

In section "Loop Editor", there are two sets of shortcodes:
[wpv-items-found] ... [/wpv-items-found]
[wpv-no-items-found] ... [/wpv-no-items-found]

You can use them to display different results "based on wether if the view has results or not".

More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-items-found
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-no-items-found

#1576951

Hello and thank you,
I have added [wpv-found-count] to the [wpv-no-items-found] ... [/wpv-no-items-found], so the view returns 0 if no post were found.
Now, I would need to insert this into a conditional display. I've tried this but it doesn't seem to work :

    [wpv-conditional if="( $([wpv-view name="related-posts" motscles="[wpv-view name='related-posts-par-mot-cle-pays']"]) ne '0' )"]CONTENT ONLY DISPLAYED IF VIEW COUNT > 0
    [/wpv-conditional]

Thank you.

#1576959

By playing with " " and ' ' it finally worked !
My issue is resolved now. Thank you!