Skip Navigation

[Resolved] I need help in creating a conditional output based on a post value

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

Problem:
How to display price conditionally

Solution:
You can use View's shortcode [wpv-conditional] to display conditional output.

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/i-need-help-in-creating-a-conditional-output-based-on-a-post-value/#post-589395

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

This support ticket is created 7 years 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 fredB-4 7 years ago.

Assisted by: Minesh.

Author
Posts
#589374
PostFields2.jpg
PostFields.jpg
Season2.jpg
Season1.jpg
View.jpg

I have a custom post [seasons] (id 73). It has one post field [choose season] with 3 values [High Season, Mid Season, Low Season].

So depending on the season it must conditionally display the Price for that Season in a view.

The posts are not related.

In the view I am able to successfully display the information (as a test to see if the information can be used in the view), but I am not able to use it in a conditional output.

I attempted to use get_post(), but this was the debug output:

####################
wpv-conditional attributes
####################
Array
(
[if] => ( get_post(73) = 'Low Season' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( get_post(73) = 'Low Season' )
--------------------

Help will be greatly appreciated!

What is the link to your site?
hidden link

#589395

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand:
- You have field choose season field using which you set the current season for your custom post seasons - correct?

Now, you want to compare the current season set using choose season field using conditional statement - correct? If this is true then:

[wpv-conditional if="( '[types field="choose-season" output="raw"][/types]' eq 'Low Season'  )"]
     [types field="low-season-price" output="raw"][/types]
[/wpv-conditional]

[wpv-conditional if="( '[types field="choose-season" output="raw"][/types]' eq 'Mid Season'  )"]
     [types field="mid-season-price" output="raw"][/types]
[/wpv-conditional]


[wpv-conditional if="( '[types field="choose-season" output="raw"][/types]' eq 'High Season'  )"]
     [types field="high-season-price" output="raw"][/types]
[/wpv-conditional]

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#numeric
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#589440

Thank you. You put me on the correct path. What worked for me was:

[wpv-conditional if="( '[types field='choose-season' id='73'][/types]' eq 'High Season' )"]From R [types field='high-season-price' output="raw"][/types] [types field='payment-per' output='raw'][/types][/wpv-conditional]
[wpv-conditional if="( '[types field='choose-season' id='73'][/types]' eq 'Mid Season' )"]From R [types field='mid-season-price' output="raw"] [/types][types field='payment-per' output='raw'][/types][/types][/wpv-conditional]
[wpv-conditional if="( '[types field='choose-season' id='73'][/types]' eq 'Low Season' )"]From R [types field='low-season-price' output="raw"] [/types][types field='payment-per' output='raw'][/types][/types][/wpv-conditional]