Skip Navigation

[Resolved] create deadline filed and add it to post grid

This support ticket is created 7 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 7 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#577024

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

#577121

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']