Skip Navigation

[Resolved] shortcode to display a timestamp plus 1 day for expiration field

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)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 1 month, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2766488

Hi there

I need a little help with this shortcode to set an expiration date on 'MAIN POST' that is one day after the custom field date of a 'RELATED POST'. Here is my setup:

1. Toolset Settings / Forms / Post expiration enabled (checking once daily)

2. Functions/ Shortcode to add 1 day to a timestamp:

function func_addoneday($atts){  
   return date('Ymd',strtotime($atts['thedate'] . ' +1 day'));
}  
add_shortcode('addoneday', 'func_addoneday'); 

3. Toolset View to get the custom date field of the related post and display it in timestamp format, plus one day, using the shortcode above. This in the loop of the related post:

[addoneday thedate="[types field='my-custom-date-field' output='raw'][/types]"]

4. Toolset form to edit the main post and set the expiration date using a generic date field and the view above:

[cred_generic_field field='myexpiration' type='date' class='' urlparam='']
  {
  "required":1,
  "validate_format":0,
  "default":"[wpv-view name='my-view-title']",
  "persist":1
  }
  [/cred_generic_field]

The problem I have is that if I set the shortcode date to return 'Ymd' and the custom field in the view to return 'Ymd' the output is perfect. For example, the end date of the related custom field is 07102024 and the output is 08102024.

However, I want to pass this date to the generic date field in the form (to trigger an email notification) and can't get the shortcode to output a timestamp format that is compatible with the generic date field.

Hoping someone can help!

Rita

#2766678

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to modify the shortcode code as given under:

function func_addoneday($atts){ 
  
  $days_to_increase = 1;
 
  $result=0;
  if(!empty($atts['thedate'])) {
   $result = $atts['thedate']+(24*60*60*$days_to_increase);
  }

 return $result;

}  
add_shortcode('addoneday', 'func_addoneday'); 

Where:
- You can dynamically set the value for $days_to_increase.

The above function will return the Unix Timestamp value for by adding the 1 day to the date you pass to above shortcode.

#2767313

That works beautifully. Thank you Minesh.