Tell us what you are trying to do?
I want to add deadline field to my posts and make it appear like countdown
also i want it to be shown in post grid like the example that i will show to you
Is there a similar example that we can see?
hidden link
this site use AFC to do the countdown but i know that Toolset is the best so i am sure that i can make it but don't know how
What is the link to your site?
hidden link
There's no built-in way to make date range calculations like this in Toolset, but I do have a custom shortcode that might help.
- Create a custom field on your post type. Make it a date field, and call it "deadline"
- Add the following code to your functions.php file:
add_shortcode( 'format_date_difference', 'format_date_difference_func');
function format_date_difference_func($atts = [])
{
$atts = shortcode_atts([
'start' => '',
'end' => '',
'format' => '%y years, %m months, %d days',
], $atts);
$datetime1 = new DateTime($atts['start']);
$datetime2 = new DateTime($atts['end']);
$interval = $datetime1->diff($datetime2);
return $interval->format($atts['format']);
}
-Then add the shortcode to your Content Template:
[format_date_difference start='[types field="deadline" format="Y-m-d"][/types]' end='' format='%a days']