Skip Navigation

[Resolved] Expiry Date not being set on CPT Nanny Ad for posts created with Toolset Form

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 simonM-5 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2562535

Hi Support

I am revisiting this production topic which Minesh worked on before but we didn't get to a conclusion, because I didn't have the time to pursue it properly.:
https://toolset.com/forums/topic/custom-field-not-being-populated-consistently/

Having reviewed the previous ticket, on re-reading it I realised that we are not talking about a custom field at all, rather the standard expiry date, which is set when you choose

"Set expiration date for post created or edited by this form" in the following Toolset forms (we want it set for to 185 days)

Post Form - New Nanny Ad (ID: 921)
Post Form - New Nanny Ad - Unverified Nanny (ID: 23430)

We have exactly the same options selected on our forms in dev, where it appears to work fine. It's just in production where it is not working correctly.

Can this please be investigated as to why the standard Expiry Date field is not being populated correctly on creation of a Nanny Ad record via the Toolset Forms mentioned.

WP Adminer is available on the production site to query the database, but please do not change anything without our consent as this is a production site.

Access details removed.

Kind regards
Simon

#2563999

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share access details for frontend user and admin for your test site where you claim its working. I'll require to review your setup why its working on your Dev site but not on your production site.

Have you added any custom code related to those forms on Devs site but not on your production site?

*** 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 have set the next reply to private which means only you and I have access to it.

#2564273
#2565243

Minesh
Supporter

Languages: English (English )

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

I've tried to add the following post on your live site from the frontend using the user you shared: nativenanny2@hotmail.com
=> hidden link

I can see that the post expiration date is set correctly.

Even I checked the database and with database as well I can see the post expiration date is set correctly. Please check the following screenshot: hidden link

I'm not sure in what term you say that the post expiration date is not set. Do you have exact steps I should follow to reproduce the issue?

#2565249
Screenshot 2023-03-03 at 13.32.43.png
Screenshot 2023-03-03 at 13.32.35.png

Hi Minesh

As I stated in the original ticket, it was not ALWAYS being set correctly. You can see this for lots of Nanny Ads in the Nanny Ads screen in the furthest right column.

For your ad, it appears you were lucky this time. Compare with (production) Nanny Ad, ID 33145 (please don't edit it):

There you can see in the top section "Nanny Ad expiration" that the expiry date appears to be set, however in the section "Field Group for Nanny Ads" the same Ad appears blank.

See screenshots...

Thanks and regards
Simon

#2565277

HI Minesh

I think I have found the problem:

Nanny Ads created with the form:
Post Form - New Nanny Ad - Unverified Nanny (ID: 23612)

are not included in the custom code snippet:

preserve-ad-expiry-date

I think the id 23612 just needs to be added to the array, like this, right?

(I'm gonna try this now on dev.native-nanny.de, but could you please confirm I am doing it right?)

add_action('cred_save_data', 'populate_nanny_ad_expiry',11,2);
function populate_nanny_ad_expiry($post_id, $form_data)
{
	// Post Form - New Nanny Ad (921)
	// Post Form - New Nanny Ad - Unverified Nanny  (ID: 23612)
	$forms = array( 921, 23612 );
	$slug = 'wpcf-nanny-ad-expiry';

	if ( in_array( $form_data['id'], $forms ) )
	{
// copy the original expiration timestamp into a hidden custom field
// for future reference, since original timestamp is reset upon expiry
	$expiry = get_post_meta( $post_id, '_cred_post_expiration_time', true );
		if( $expiry && $expiry !='0' ) 
		{
			update_post_meta( $post_id, $slug, $expiry );
		}
	}
}

Kind regards
Simon

#2565285

HI Minesh

That appears to have worked in dev.

So, it looks like the original expiry date is getting set correctly for all the Ads. This makes sense. The code was written at a time before the introduction of the Post Form - New Nanny Ad - Unverified Nanny (ID: 23612).

However, we would need to update the Expiry Date field with the same value from the original expiry date set for all those Nanny Ads which don't have it. What would be your recommendation for doing this? Just by some SQL statement on the database? Is that permissible or will that screw something else up?

Kind regards
Simon

#2565405

Minesh
Supporter

Languages: English (English )

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

Glad to know that you able to locate the issue.

You will have to write your own script to update the custom field value based on your requirement. Such custom script falls outside the scope of our support policy. You can always contact our certified partners for such custom programming work.

You can always contact our certified partners:
=> https://toolset.com/contractors/

#2566167

Hi Minesh

I managed to solve the rest by adding the missing records to the wp_postmeta table directly on the database.

Thanks and regards
Simon

#2566169

My issue is resolved now. Thank you!