Skip Navigation

[Resolved] Nested condition within condition

This support ticket is created 3 years, 8 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 12 replies, has 2 voices.

Last updated by deepS 3 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1979299

Hi,
I have exam posts type containing RFGs viz. Date fields. It has two field types like 'Application Starting Date' (assigned code '3') and 'Application Closing Date' (assigned code '4'). The possible scenarios are:
<b>1. Starting date > Today and Closing date> Today:</b> Display only Starting Date
<b>2. Starting date<Today and Closing date> Today:</b> Display only Closing Date

In scenario 1, the code is:

[wpv-conditional if="( $(wpcf-exam-date) gte 'Today()' ) AND ( $(wpcf-exam-event-type) eq '3') AND ( $(wpcf-exam-date) ne '' )"]Application Starts: [types field='exam-date' style='text' format='jS M y'][/types][/wpv-conditional]

In scenario 2, I need to compare the Starting date (generated by another conditional code) with Today. Hence I made the following conditional code:

[wpv-conditional if="( $(wpcf-exam-date) gte 'Today()' ) AND ( $(wpcf-exam-event-type) eq '4') AND ( $(wpcf-exam-date) ne '' ) AND '[wpv-conditional if="( $(wpcf-exam-event-type) eq '3') AND ( $(wpcf-exam-date) ne '' )"]"[types field='exam-date' output='raw'][/types]"[/wpv-conditional]' lt 'Today()'"]Registration Closes on: [types field='exam-date' style='text' format='jS M y'][/types][/wpv-conditional]

Here the conditional code is breaking. I have tried using the content template for the nested code. But the code is not behaving its way. Please help me to resolve the issue. Thanks.

#1979343

Hello,

For the scenario 2, you can use "OR" Boolean operator, like this:

[wpv-conditional if="
($(wpcf-exam-date) ne '') AND ( ($(wpcf-exam-date) gte 'Today()')  AND ($(wpcf-exam-event-type) eq '4') ) OR ( ($(wpcf-exam-date) lt 'Today()')  AND ($(wpcf-exam-event-type) eq '3') )
"]
Registration Closes on: [types field='exam-date' style='text' format='jS M y'][/types]
[/wpv-conditional]

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional
Boolean operators: AND, OR, NOT

#1979395

Thanks for your reply.
I think the previous code needs to be modified. As we put OR (it should be AND) it's showing both the dates (Start and closing). While we put AND it shows nothing. Please have a look. Thanks.

#1979401

Please elaborate the question with more details:
Which "previous code" need to be modified?
When does it show both the dates (Start and closing)?

Please provide detail steps to reproduce the same problem, thanks

#1979447

The previous code is the code you have provided. See the argument should be like this:
Example 1:
Start date: 7 April 2021
Closing date: 27 April 2021
In this case, it should display only the Start date i.e. 7 April 2021 since both the dates are greater than Today.

Example 2:
Start date: 7 March 2021
Closing date: 27 April 2021
In this case, it should display only the Closing date i.e. 27 April 2012 since the Start date is lesser than Today, but the Closing date is greater than Today.

Hope I can make you understand the issue. Thanks.

#1979517

I don't know why my previous reply is not showing up. I am writing it once again.
For previous code mean the code provided by you.

Please see the examples below:
Example 1:
Starting date: 07 April 2021
Closing Date: 27 April 2021
It should display the starting date i.e. 07 April 2021 since both the dates are greater than Today.

Example 2:
Starting date: 07 March 2021
Closing Date: 27 April 2021
It should display the Closing date i.e. 27 April 2021 since the Start date is lesser than Today and the Closing date is greater than Today.

Hope I can make you understand. Thanks.

#1980451

It is not clear, how do you setup the "Starting date" date field and "Closing Date" date field?

You can follow the document I mentioned above to setup the wpv-conditional shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

if you need more assistance for it, please provide a test site with the same problem, also point out the problem page URL.

#1981741

Thanks for the details, Toolset repeatable field group is based on one-to-many post type relationship, so each item of repeatable field group is also a single post, the post type slug is same as the "repeatable field group" slug, in your case, it is "exam-dates".

please check it in your website:
hidden link
The "Starting Date of Application" is a "exam-dates" post(item of repeatable field group), it isn't a custom date field.
Same as above, the "Last date of Application" is also another "exam-dates" post.

Those two custom date fields are not in the same "exam-dates" post, so you can not use wpv-conditional shortcode to get what you want, and there isn't such kind of built-in feature within Toolset plugins

In this case, it needs custom codes, for example:
1) Add a custom shortcode with a PHP function:
https://codex.wordpress.org/Shortcode_API
2) In this PHP function, setup custom PHP codes to:
- Query posts of post type "exam-dates"
- Filter by:
a) field "wpcf-exam-event" = "Starting Date of Application" AND "wpcf-exam-date" < today's timestamp
Or
b) field "wpcf-exam-event" = "Starting Date of Application" AND "wpcf-exam-date" < today's timestamp
- if the result are 2 posts, then output the "Starting Date of Application" post's "exam-date" field value
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters

Same as above, you can output the "Last date of Application" post's "exam-date" field value when the result satisfied specific condition.

In my opinion, there is a easy workaround, you can simply add two custom date fields into post type "Exam":
- Starting Date of Application
- Last date of Application
Edit each "exam" post, setup above date fields value
Then follow the document I mentioned above to display the different result with [wpv-conditional] shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

For your reference.

#1981853

As I am a layman, it would be much helpful for me if can create the shortcode for me. Thanks.

#1983095

Unfortunately, according to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/

And I don't think it is a good idea to use custom codes in your case, for example, if you fill into field "exam-event" with little different value "Starting Date of Applications", the custom codes won't work.

Please check the workaround I mentioned above:
https://toolset.com/forums/topic/nested-condition-within-condition/#post-1981741

#1983423

See the 'Event Type' is a dropdown list so it has fixed values.

#1983499

My above answer might not be clear.
1) according to our support policy, we don't provide custom codes support
https://toolset.com/toolset-support-policy/

We cannot produce custom code solutions for you. When you need custom coding which extends Toolset functionality, we recommend contacting one of Toolset certified consultants.

2) And I still don't think it is a good idea to setup the custom codes in your case, it will conduct other problems, for example, the shortcode need to run in the each item of views loop, and conduct performance problem

Did you check the workaround I mentioned above?
https://toolset.com/forums/topic/nested-condition-within-condition/#post-1981741

you can simply add two custom date fields into post type "Exam"
...

#1983529

My issue is resolved now. Thank you!