I'd like to have text show up in a view/content template based on a date.
So:
[If today's date is before Feb 28 at 9am then SHOW] text here [/conditional]
[If today's date is between Feb 28 at 9am and March 15 at 9am then SHOW] text here [/conditional]
[If today's date is after March 1 at 9am then SHOW] text [/conditional]
Can you help with the shortcode for this? This will be in a classic view. here is a sample of what I have now based on other conditions, but I need to add the date element as well.
Hello. Thank you for contacting the Toolset support.
I would like to just clarify that do you have any custom date field and you want to compare the custom date field value against date value like "before Feb 28 at 9am" or you just want to compare the value like "before Feb 28 at 9am" with current "today's" date?
add_shortcode('compare_current_date_time','func_compare_current_date_time');
function func_compare_current_date_time($atts,$content){
if(isset($atts['before']) and !empty($atts['before'])){
if(time() < strtotime($atts['before']))
return 1;
else
return 0;
}
if(isset($atts['between']) and !empty($atts['between'])){
$dates = explode("|",$atts['between']);
if ((time() >= $dates[0] && time() <= $dates[1]))
return 1;
else
return 0;
}
if(isset($atts['after']) and !empty($atts['after'])){
if(time() > strtotime($atts['after']))
return 1;
else
return 0;
}
}
Once you add and activate the ccode snippet, please regiter the custom shortcode name compare_current_date_time at:
=> go to the Toolset -> Settings page, click the Front-end Content tab and add your shortcode name in the Third-party shortcode arguments section.
Now, you can add the following conditionoal statements to check the current date againsts provided date values of before/after/between.
Compare crrent date Before:
[wpv-conditional if="( '[compare_current_date_time before='2025-02-28 9:00:00']' eq '1' )"]
//// current date is less than (before) the provided date
[/wpv-conditional]
Compare crrent date Between:
[wpv-conditional if="('[compare_current_date_time between='2025-02-28 9:00:00|2025-03-15 9:00:00']' eq '1' )"]
////current date is beweeen provided dates (start-date|end-date):2025-02-28 9:00:00|2025-03-15 9:00:00
[/wpv-conditional]
Compare crrent date After:
[wpv-conditional if="( '[compare_current_date_time after='2025-03-01 00:00:00']' eq '1' )"]
//// current date is greater than (after) the provided date
[/wpv-conditional]
Can you please share problem URL and admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Thank you for sharing admin access details but when I try to login using the admin access details you shared I see the error:
"Error: The username toolset is not registered on this site. If you are unsure of your username, try your email address instead."
Can you please send me working admin access details.
I have set the next reply to private which means only you and I have access to it.
[wpv-conditional if="( '[compare_current_date_time before='2025-02-14 9:00:00']' eq '1' )" debug='false']
//// current date is less than (before) the provided date
[/wpv-conditional]
[wpv-conditional if="('[compare_current_date_time between='2025-02-23 9:00:00|2025-03-15 9:00:00']' eq '1' )"]
////current date is beweeen provided dates (start-date|end-date):2025-02-28 9:00:00|2025-03-15 9:00:00
[/wpv-conditional]
[wpv-conditional if="( '[compare_current_date_time after='2025-03-01 00:00:00']' eq '1' )"]
//// current date is greater than (after) the provided date
[/wpv-conditional]
Can you please confirm its working as expected now.
As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.