Skip Navigation

[Resolved] Date multi-fields calculation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Date multi-fields calculation

Solution:
To calculate the repeating date field value or multiple instance of date field value. You need custom shortcode.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/date-multi-fields-calculation/#post-1096333

Relevant Documentation:

This support ticket is created 6 years, 2 months 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
- 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 8 replies, has 2 voices.

Last updated by domenicoS 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1095761

Hi,

I'm trying to display a date after a calculation done with php function.

I've 2 custom field:
- 'patenze': is a multi-date fields
- 'release': is a numeric fields

I used this funtion:

function date_calculation($atts){
$post = get_post();	 
$days_release = get_post_meta( $post->ID, 'wpcf-release', true );
$date_partenza = get_post_meta( $post->ID, 'wpcf-partenze', true ); 
$convert_release = ($days_release * 24 * 60 * 60); 
$date_chiusura = ($date_partenza - $convert_release); 
 
 
return date('d/m/Y',$date_chiusura);

}

I used also this code for display it in layout:

<table class="table table-bordered">
<body>
  <tr>
      <th scope="col">Partenze</th>
      <th scope="col">Chiusura iscrizioni</th>
    </tr>
<tr>
  <td> [types field='partenze' style='text' format='j F Y' separator=' </td><td> [booking-deadline]</td></tr><tr><td>'][/types]</td><td> [booking-deadline]</td></tr>
  </body>
  </table>

This is the page where layout is displayed: hidden link

ISSUE:

My problem is when I add more date with the multi-fields.

The function calculate the right value only for the first date but not for the otherones.
Infact for the otherones is displayed the same date of the firstone

Can you help me? What you suggest?

There is another solution or something is wrong?

Thanks guys!

#1096030

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - as you told that patenze is repeating date field.

To loop through the repeating date field - could you please try to use following code:

function date_calculation($atts){
global $post;

$days_release = get_post_meta( $post->ID, 'wpcf-release', true );
$date_partenza = $atts['date'];

$convert_release = ($days_release * 24 * 60 * 60); 
$date_chiusura = ($date_partenza - $convert_release); 
  
return date('d/m/Y',$date_chiusura);

}

And call the code as given under:

[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>
</tr>
[/wpv-for-each]

More info:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

#1096281

Hi,

It doesn't works. it giv me a wrond date.

I added with the custom fied 2 date:

- 27 agosto 2018
- 1 novembre 2018

And the numeric filed is set on 20.

With my previus code it give me
- 7/8/2018 (it was right)
- 7/8/2018 (it was wrong because for the second date it should be 11/11/2018)

With you code it give me:
- 12/12/1969
-12/12/1969

Bothe are 20 days before the defoult date 1-1-70 and not of my custom dates

#1096284

Minesh
Supporter

Languages: English (English )

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

Can I have problem URL and access details.

I have set next reply as private.

#1096304

Minesh
Supporter

Languages: English (English )

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

Unfortunately - wp-admin access details are not working. Could you please send me working access details.

Additionally - please share FTP access details so that I can change the custom shortcode you added accordingly.

I have set the next reply to private which means only you and I have access to it.

#1096307

Sorry I miss the ftp. Please sign the next answer to dive you the credential

#1096318

Minesh
Supporter

Languages: English (English )

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

I have set the next reply to private which means only you and I have access to it.

#1096333

Minesh
Supporter

Languages: English (English )

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

Could you please check now:

I've adjust the code as given under:

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");

And called the shortcocde as given under:

[wpv-for-each field='wpcf-partenze']
<tr>
 <td> [types field='partenze' style='text' format='j F Y'][/types]</td>
<td> [booking-deadline]</td>
</tr>
[/wpv-for-each]

I see we have accurate and expected result now. Could you please confirm.

#1096335

Thank you, it works!
Great support