Skip Navigation

[Resolved] Views Output in Conditional Won’t Match

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

Problem:
Views Output in Conditional Won't Match

Solution:

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/views-output-in-conditional-wont-match/#post-1275473

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

This support ticket is created 5 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by laneV 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1275313

I have a view with the sole purpose of counting how many items are related to a post ID. To prevent the output from wrapping in a div that I can't seem to add a class to for formatting, I pass a param via the view shortcode to modify the output to only return the [wpv-found-count]. I call this view like:

[wpv-view name="count-items-in-relationship" wpvrelatedto="[wpv-post-id]" version="short"]

In my view I have the following conditional:

[wpv-conditional if="( '[wpv-attribute name="version"]' eq 'short' )"][wpv-found-count][/wpv-conditional]

The view does display the count number correctly. Now, when I try to use the output of that view in a conditional to determine if my output term is singular or plural I can't seem to get it to match. I've tried combinations of using and not using single quotes with no luck. I've tried the following but none of the conditionals end up matching:

[wpv-conditional if="( [wpv-view name="count-items-in-relationship" wpvrelatedto="[wpv-post-id]" version="short"] ne 0 )"]![/wpv-conditional]
[wpv-conditional if="( '[wpv-view name="count-items-in-relationship" wpvrelatedto="[wpv-post-id]" version="short"]' ne 0 )"]@[/wpv-conditional]
[wpv-conditional if="( [wpv-view name="count-items-in-relationship" wpvrelatedto="[wpv-post-id]" version="short"] ne '0' )"]#[/wpv-conditional]
[wpv-conditional if="( '[wpv-view name="count-items-in-relationship" wpvrelatedto="[wpv-post-id]" version="short"]' ne '0' )"]$[/wpv-conditional]

I can't find an explanation in the documentation. Am I missing something? Is there a better way to do this?

#1275473

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Views offers a way to be able to display the view output list inline.

You can checkmark the checkbox "Disable the wrapping DIV around the View" available just under the "Loop Editor" section to raw output the view result and then yon can use it with conditional statement.

#1275781

Thank you Minesh, I've seen that checkbox a million times and it just didn't "click" for me.

The view still passed back some unexpected whitespace so I can't use the return value in my conditional. However, I moved conditionals into the count view so that it returns proper links and singular/plural. This way seems faster as the page load more quickly.