Skip Navigation

[Resolved] How to change [wpv-post-date] into today when submitting the cred-form

This support ticket is created 7 years, 11 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 mcjS 7 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#397479

After updating all the plugins to the latest versions, there is a function that is not working anymore.
This was the thread before:

https://toolset.com/forums/topic/change-wpv-post-date-into-today-when-submitting-the-cred-form/

and I'm using this code in functions.php:

// verlengen met post_date = today en verloopdatum = today plus 65 dagen
add_action('cred_save_data_2141', 'save_data_for_form_with_id_2141',10,2);
function save_data_for_form_with_id_2141($post_id, $form_data) {
$my_post = array(
'ID' => $post_id,
'post_date' => date_i18n( 'Y-m-d h:i:s', localtime()),
);
$res = wp_update_post( $my_post, true ); //change the [wpv-post-date] into today
update_post_meta($post_id, '_cred_post_expiration_time', time()+65*24*60*60); //set the expiry date in today plus 65 days
}

the date isn't changing anymore?

i'm using WordPress 4.5.2
and toolset CRED Versie: 1.6
(i don't know where to find the debug information?)

#397623

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I do not see any issue with the code.

Regarding the debug information - we are in process of updating that process:
https://toolset.com/faq/provide-debug-information-faster-support/

1)
Could you please activate WP_DEBUG from wp-config.php file and send me possible errors for review.

2)
if #1 does not help.

Could you please share link of the page where you've added your CRED form.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#399421

Minesh
Supporter

Languages: English (English )

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

I checked your issue and strange thing is that when I try to test first time, it calls the "cred_save_data" hook successfully and after that it just redirects to another page and "cred_save_data" hook hook it not called. It's really tstrange.

I suggest:
Could you please try to resolve your issue by deactivating all third-party plugins as well as with the default theme to check for any possible conflicts with any of the plugins or themes?

#399473

I deactivated all 3rd party plugins & I activated theme 2016, problem is still there?

#399805

Minesh
Supporter

Languages: English (English )

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

I checked with default 2016 theme, you did not added CRED hook 'cred_save_data' to your current theme 2016 functions.php file.

I made a test by adding following code to your 2016 theme's functions.php file:

add_action('cred_save_data_2141', 'save_data_for_form_with_id_2141',10,2);
function save_data_for_form_with_id_2141($post_id, $form_data) {
	
echo "<pre>";
print_r($_POST);
//echo date_i18n( 'Y-m-d h:i:s', localtime());
//echo "localtime=>".localtime();

print_r(localtime());

exit;
}

I can see that hook is called perfectly.

Now, as far as I can see the issue is from this line of code: date_i18n( 'Y-m-d h:i:s', localtime());,

Could you plese try to check by replacing above code with some static value and check if that works or is this issue comes from your theme, or PHP version.

date_i18n() accept second parameter as unix timestamp but here localtime() returns value as array, you may try to check this as well.

#399868
warning.gif

I tested form 2141 (on the website for a specific ad) and this is the result:

Array
(
[wpcf-website] =>
[merk] => Array
(
[0] => 29
)

[new_tax_text_merk] =>
[new_tax_select_merk] => -1
[soort] => Array
(
[0] => 35
)

[new_tax_text_soort] =>
[new_tax_select_soort] => -1
[wpcf-bouwjaar] => 1980
[wpcf-slaapplaatsen] => 2
[wpcf-lengte] => 640
[wpcf-prijs] => 19800
[wpcf-kilometerstand] => 225538
[wpcf-foto] => Array
(
[0] => hidden link
[1] => hidden link
[2] => hidden link
[3] => hidden link
[4] => hidden link
)

[form_submit_2] => Wijzig advertentie
[_cred_cred_wpnonce] => 63a421d5bd
[_cred_cred_prefix_post_id] => 12739
[_cred_cred_prefix_cred_container_id] => 12739
[_cred_cred_prefix_form_id] => 2141
[_cred_cred_prefix_form_count] => 1
)
Array
(
[0] => 1
[1] => 11
[2] => 14
[3] => 19
[4] => 4
[5] => 116
[6] => 4
[7] => 139
[8] => 0
)

AND
When I used first the code I wrote in the first item of this thread, I saw an error you can see in the screenshot.
(without your specific test code)

#400136

Minesh
Supporter

Languages: English (English )

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

Yes - I shared that code in my previous reply that I've tried to add the said code to your default theme's functions.php file.

I suggest:
- remove 'cred_save_data_2141' hook from your current theme's function.php file.
- copy your CRED forms related "cred_save_data_xx" hooks code from 'Camper' theme's functions.php file and paste it to your default theme's (twentysixteen) functions.php file.
(make sure you have copy all 'cred_save_data' hooks which your CRED forms are using )
- I think the errors is due to 'date_i18n()' function that accept second parameter as unix timestamp but here localtime() returns value as array, you may try to check this instated of some default value.

For example:

$my_post = array(
'ID' => $post_id,
//'post_date' => date_i18n( 'Y-m-d h:i:s', localtime()),   I've commented this line
'post_date' => 'HERE-TRY-WITH-SOME-DEFAULT-VALUE',  
);
#400166

When I'm using a hard code date & time, the function is working,

$my_post = array(
'ID' => $post_id,
//'post_date' => date_i18n( 'Y-m-d h:i:s', localtime()),
'post_date' => '2016/05/20 12:20:48',
);

the post-date changed into 20-05-2016 12.20.48 (European)

"I think the errors is due to 'date_i18n()' function that accept second parameter as unix timestamp but here localtime() returns value as array, you may try to check this instated of some default value."

But: How do I change the date automatically if date_i18n() isn't always working good?
My client want to change the postdate into today plus 65 days, but also with local time (Amsterdam - Western Europa)

"but here localtime() returns value as array" sorry I'm not a PHP coder,
that was the reason I asked Toolset for help:
https://toolset.com/forums/topic/change-wpv-post-date-into-today-when-submitting-the-cred-form/

I installed the plugin WordPress phpinfo() for system information:

PHP Version 5.6.21
System Linux www70.totaalholding.nl 2.6.32-673.8.1.lve1.4.3.el6.x86_64 #1 SMP Wed Feb 10 08:57:30 EST 2016 x86_64

it is also unix, and the original (live) site (without updates) has this information:
PHP Version 5.6.20-0+deb8u1
System Linux hosting 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24) x86_64

Is there a difference in system - date / localtime?

#400174

Minesh: Tnx for helping me so far.
Now I know which piece of code the problem is, I ask someone else for help, outside Toolset support.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.