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!
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
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
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.
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.
Sorry I miss the ftp. Please sign the next answer to dive you the credential
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.
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.
Thank you, it works!
Great support