Skip Navigation

[Resolved] Condition in CRED Form based on Views with output [wpv-found-count]

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

Problem:
How to use the found count of a View in a conditional statement?

A View outputs just the found count—using the wpv-found-count shortcode—but it doesn't work when used in a conditional shortcode that tests the resulting number.

Solution:
The problem is that the View doesn't just output the number, it includes a wrapper div and some white space.

The wrapper div can be disabled with its setting, and the whole of the Loop Output can be compressed to eliminate whitespace, like so:

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

That will then output just the number with no extra whitespace or markup and so can be used in a conditional shortcode.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 5 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by JakubV7709 5 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1326799

Hi,

i setup view which works and give me number (count) of author posts.

[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
[wpv-found-count]
    <wpv-loop>
 
    </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
      [wpml-string context="wpv-views"][/wpml-string]
    [/wpv-no-items-found]
[wpv-layout-end]

Output is correct = only number like 2 or 3 etc.

I would like to setup condition in cred form based on this number. This code give me just the number from view. Its ok.

  [wpv-view name="form-pocet-clanku-pro-omezeni"]

But if i create condition in CRED Form based on output from the view above it doesnt work:

[wpv-conditional if="( '[wpv-view name='form-pocet-clanku-pro-omezeni']' gt '1' )"]More than one[/wpv-conditional]

Is it possible to setup condition based on this number form view? Thank you

#1326919

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Jakub

If you output the View and it shows you the number as expected, if you use your browser dev tools you are likely to see that the number is contained inside a wrapper div, so it's not just a number.

You can use the setting to disable the wrapper div (in the Loop Editor section) which should then just output the number.

Try that, and let me know how that goes.

#1326947

Hi Nigel,

i select Disable the wrapping DIV around the View in the Loop Editor section -> . is it correct?

But the condition in cred form doesnt work after this update of view.

#1326985

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The problem is probably because of whitespace that is collapsed by the browser when displaying the number but which affects the conditional shortcode.

Can you edit your View to remove all the whitespace.

In my sample site (where I tested this and it worked) my Loop Editor looked like this:

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

I was then able to successfully use the View in a conditional shortcode.

#1326987

My issue is resolved now. Thank you!