Home › Toolset Professional Support › [Resolved] Comparation date
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)
Tagged: Front-end display, Layouts plugin
This topic contains 15 replies, has 5 voices.
Last updated by Minesh 6 years, 2 months ago.
Assisted by: Minesh.
Hi,
I've created a conditional display of dates after upload a custom code in function.
It works great, but now I need to add another comparation:
I've 3 date:
- date 1 from custom multi-field [partenze]
- date 2 from function calculation and custom shortcode [booking-deadline]
- date 3 is today date [today]
What I need is to compare this 2 dates and display a result. These are the conditions:
- if [partenze] is equal to [today] = Close
- if [booking-deadline] is equal to [today] = Last day
- if [partenze] is lower then [today] and [booking-deadline] is lower then [today]= Close
- if [partenze] is greater then [today] and [booking-deadline] is lower then [today]= On request
- if [partenze] is greater then [today] and [booking-deadline] is greater then [today]= Open
This is the code I used:
[wpv-for-each field='wpcf-partenze'] <tr> <td> [types field='partenze' style='text' format='j F Y'][/types]</td> <td> [booking-deadline date="[types field='partenze' output=''raw][/types]"]</td> <td> [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' lt '[today]' ) AND ( '[types field='booking-deadline' style='text' format='U'][/types]' lt '[today]' )"] Close[/wpv-conditional] [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' gt '[today]' ) AND ( '[types field='booking-deadline' style='text' format='U'][/types]' lt '[today]' )"] On request[/wpv-conditional] [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' gt '[today]' ) AND ( '[types field='booking-deadline' style='text' format='U'][/types]' gt '[today]' )"] Open[/wpv-conditional] [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' eq '[today]' )"] Close[/wpv-conditional] [wpv-conditional if="( '[types field='booking-deadline' style='text' format='U'][/types]' eq '[today]' )"] Last day[/wpv-conditional] </tr> [/wpv-for-each]
The problem seem to be with the comparation to [booking-deadline]. Seem doen't read as date or similar..
For example the simple comparation one-to-one give me a wrong result. It should be "Last day" but is "On request"
[wpv-conditional if="( '[types field='booking-deadline' style='text' format='U'][/types]' eq '[today]' )"] Last day[/wpv-conditional]
Can you help me?
This is the result page: hidden link
OK, [booking-deadline] is not our Shortcode - this is a Custom ShortCode that I do not know what it returns.
Instead, [types field='booking-deadline' etc] is a Types (probably date) field.
Now, Toolset Date Fields do store Unix Timestamps and can return those as well (output raw).
To compare such values you would then need to compare this to another Timestamp, so it is crucial to know what [booking-deadline] returns.
You can find out by simply putting both Shortcodes ([types field='booking-deadline' style='text' format='U'][/types] and [booking-deadline] into a post or view.
The values returned, are what you will compare.
If one is a timestamp (something like 3218904) and a Date (like 11 August 2017) then the comparison fails.
You need to compare both to the Timestamp
Hi Beda, this is the function I used:
// Booking deadline calculation function date_calculation($atts){ global $post; static $i = 0; $days_release = get_post_meta( $post->ID, 'wpcf-release', true ); $date_partenza = get_post_meta( $post->ID, 'wpcf-partenze'); $convert_release = ($days_release * 24 * 60 * 60); $date_chiusura = ($date_partenza[$i++] - $convert_release); return date('d/m/Y',$date_chiusura); } add_shortcode("booking-deadline", "date_calculation"); // Today Shortcode function today_shortcode() { return mktime(0,0,0); } add_shortcode('today', 'today_shortcode');
'Partenze' is a multi field o dates
'release' is a numeric field
Thanks for your help
Hi, please go to Toolset > Settings > Frontend Content and scroll down to "Functions inside conditional evaluations". Make sure "today" is added here so it will be accepted in a conditional. Then turn on debugging for each conditional like this:
[wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' lt '[today]' ) AND ( '[types field='booking-deadline' style='text' format='U'][/types]' lt '[today]' )" debug="true"] Close[/wpv-conditional] [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' gt '[today]' ) AND ( '[types field='booking-deadline' style='text' format='U'][/types]' lt '[today]' )" debug="true"] On request[/wpv-conditional] [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' gt '[today]' ) AND ( '[types field='booking-deadline' style='text' format='U'][/types]' gt '[today]' )" debug="true"] Open[/wpv-conditional] [wpv-conditional if="( '[types field='partenze' style='text' format='U'][/types]' eq '[today]' )" debug="true"] Close[/wpv-conditional] [wpv-conditional if="( '[types field='booking-deadline' style='text' format='U'][/types]' eq '[today]' )" debug="true"] Last day[/wpv-conditional]
Reload the page and some debug information will be displayed for each conditional. Please let me know what you find.
Hi,
This is returned
#################### wpv-conditional attributes #################### Array ( [if] => ( '1535328000 1541030400 1535673600 1536278400 1538265600' < '1535932800' ) AND ( '' < '1535932800' ) [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( '1535328000 1541030400 1535673600 1536278400 1538265600' < '1535932800' ) AND ( '' < '1535932800' ) -------------------- After replacing 1 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' < 1535932800 ) AND ( '' < 1535932800 ) Comparing 1535328000 1541030400 1535673600 1536278400 1538265600 to 1535932800 After replacing 2 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' < 1535932800 ) AND ( '' < 1535932800 ) Comparing to 1535932800
#################### wpv-conditional attributes #################### Array ( [if] => ( '1535328000 1541030400 1535673600 1536278400 1538265600' > '1535932800' ) AND ( '' < '1535932800' ) [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( '1535328000 1541030400 1535673600 1536278400 1538265600' > '1535932800' ) AND ( '' < '1535932800' ) -------------------- After replacing 1 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' > 1535932800 ) AND ( '' < 1535932800 ) Comparing 1535328000 1541030400 1535673600 1536278400 1538265600 to 1535932800 After replacing 2 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' > 1535932800 ) AND ( '' < 1535932800 ) Comparing to 1535932800
#################### wpv-conditional attributes #################### Array ( [if] => ( '1535328000 1541030400 1535673600 1536278400 1538265600' > '1535932800' ) AND ( '' > '1535932800' ) [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( '1535328000 1541030400 1535673600 1536278400 1538265600' > '1535932800' ) AND ( '' > '1535932800' ) -------------------- After replacing 1 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' > 1535932800 ) AND ( '' > 1535932800 ) Comparing 1535328000 1541030400 1535673600 1536278400 1538265600 to 1535932800 After replacing 2 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' > 1535932800 ) AND ( '' > 1535932800 ) Comparing to 1535932800
#################### wpv-conditional attributes #################### Array ( [if] => ( '1535328000 1541030400 1535673600 1536278400 1538265600' = '1535932800' ) [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( '1535328000 1541030400 1535673600 1536278400 1538265600' = '1535932800' ) -------------------- After replacing 1 general variables and comparing strings: ( '1535328000 1541030400 1535673600 1536278400 1538265600' = 1535932800 ) Comparing 1535328000 1541030400 1535673600 1536278400 1538265600 to 1535932800
#################### wpv-conditional attributes #################### Array ( [if] => ( '' = '1535932800' ) [debug] => true ) #################### Debug information #################### -------------------- Original expression: ( '' = '1535932800' ) -------------------- After replacing 1 general variables and comparing strings: ( '' = 1535932800 ) Comparing to 1535932800
Hi,
I try to find the solution.
I changed the code for the debug in this way:
[wpv-conditional if="( '[booking-deadline date='[types field='partenze' output=''raw][/types]']' eq '[today]' )" debug="true"] Last day[/wpv-conditional]
In this way it give me the date, but is non comparable as format.
I've to compare 3 elements:
- date 1 from custom multi-field [partenze]
- date 2 from function calculation and custom shortcode [booking-deadline]
- date 3 is today date [today]
the solution should be to have [booking-deadline] in timestamp format
But I need also to have it in date format
Which code I've to add to have both? I tried with this:
// Booking deadline calculation function date_calculation($atts){ global $post; static $i = 0; $days_release = get_post_meta( $post->ID, 'wpcf-release', true ); $date_partenza = get_post_meta( $post->ID, 'wpcf-partenze'); $convert_release = ($days_release * 24 * 60 * 60); $date_chiusura = ($date_partenza[$i++] - $convert_release); return date('d/m/Y',$date_chiusura); } add_shortcode("booking-deadline", "date_calculation"); // Booking Deadline Timestamp Shortcode function booking_timestamp_shortcode() { return strtotime($date_chiusura); } add_shortcode('booking_timestamp', 'booking_timestamp_shortcode');
But it is wrong. How can I fix it?
Hi Domenico,
Christian is currently on a public holiday today but he will be back tomorrow to continue helping here.
Thanks,
Shane
You can add an attribute to your date_calculation shortcode to produce either a timestamp or a formatted date:
// Booking deadline calculation function date_calculation($atts){ global $post; static $i = 0; $a = shortcode_atts( array( 'format' => 'U' ), $atts ); $days_release = get_post_meta( $post->ID, 'wpcf-release', true ); $date_partenza = get_post_meta( $post->ID, 'wpcf-partenze'); $convert_release = ($days_release * 24 * 60 * 60); $date_chiusura = ($date_partenza[$i++] - $convert_release); return date($a['format'],$date_chiusura); }
Then in your shortcode, you can add the format attribute to specify the format you want to return:
[booking-deadline format='d/m/Y'] // this will show a date in the format d/m/Y [booking-deadline] // this will show a timestamp since the default format is U
I'm not able to fix this issue. I tried in many way but nothing seem to works.
Can you help me to build the right conditionale code?
Or a funtion as well..
I've 3 output in the table
- the first arrive from a multi-field date"partenze" (ok)
- the secondon from the shortecode [booking-deadline] and the relative funtion. It chages in base of "partenze" (ok)
- and here I've a sentence in base of a comparation with "partenze, [booking-deadline] and [today]
To define Booking-deadline code Minesh help me, maybe him can help also on this issue?
Hello domenicoS,
I would be happy to help you BUT could you please tell me what is not working and on which page and share access details.
I will check and try to fix your issue.
I have set the next reply to private which means only you and I have access to it.
Yes - within [wpv-for-each] shrotcode [wpv-conditional] shortcode is not supported.
So, I'm checking the following post but I do not see the "booking-deadline" field. Where is "booking-deadline" stored?:
=> hidden link
Once you share above information, I will try to formulate the solution for you.
Hi,
the shortecode booking-deadline is stored in the layout I share with you (tour layout) at ROW 8.
=> hidden link
It's a table with 3 columns. The firstone returned the date from multi-field. The secondone returned the booking-deadline shortocode. And the lastone should returned the compartion result.
Ohh, so, I wonder why you want to check the booking-deadline shortcode as that shortcode is using already the partenze date field value.
So, as I understand you want to display such status like (Close, Last Day, Open) based on the date value of field partenze. Correct?
Not only in base of field "partenze" but also in base of the field "booking deadline".
1) The field "partenze" is the departure date, when the tour start
2) the field "booking deadline" (which is the result from function) is the date when the direct booking close.
So after the booking deadline date the customer wil not book directly but he can book on requst, untill the departuree date. After the departure date the booking will be closed.
So we have 3 status:
Open: if the booking deadline (and the departure date) date will come
On request: if today is between booking deadline date (passed) and departure date (future)
Closed: if the the both, the departure date and booking deadline date, have already passed
I hope is more clear now