Skip Navigation

[Resolved] Post type fields are not saved correctly

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

Problem:
How to convert old relationship code to new relationship

Solution:
New relationship content is stored in custom tables created by Toolset.

You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/post-type-fields-are-not-saved-correctly/#post-1269113

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts

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

Last updated by Pascal 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1267625

I am trying to:

when saving a post that contains custom fields of type post reference. These fields are no longer saved. We created some documents in the past which contained post references to a WOO product and other customer post types. When saving the post_meta would then contain the field and the value would be the id of the referred post. Yesterday however we noticed that for new posts these meta fields are no longer created. When opening the post it still shows the selected post. However the meta is not being saved. The posts we created earlier (months ago) still have the meta fields. Can you please explain what could cause this?

Link to a page where the issue can be seen:

It is not public available. One of the posts where we use this is: 'transfer'. One of the post reference fields is: 'transfer-product-reference'.

I expected to see:

Meta fields containing post reference id.

Instead, I got:

Missing meta fields for the referred posts.

#1267791

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

First of all - After checking to debug information you shared with us, I found that you are using outdated WordPress version. Can you please update WordPress to the current version?
=> https://wordpress.org/download/

In addition to that, can you please share problem URL where I can see the fields are not saved correctly and what fields I need to look at it?

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

#1268843

Minesh
Supporter

Languages: English (English )

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

Well - the access details you shared with me is not working at this end.

Can you please send me working access details.

In addition to this, we do not recommend to debug the issue on live site. Is it possible for you to create a test site which should be 1:1 clone of your production site and send me access details?

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

#1268895

Btw. it stopped working since we've updated toolset to the latest version!

#1268921

Minesh
Supporter

Languages: English (English )

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

Thank you for sharing working access details. I checked the link you shared with me.

I checked this post and changed the "Product" field value (post reference field) and I see its successfully changed. Am I missing anything here?
=> hidden link

#1269015
Screenshot 2019-06-14 11.20.14.png

Yes you are missing the fact that we cannot get the reference back in a get_post_meta call (https://developer.wordpress.org/reference/functions/get_post_meta/) as stated in the first post. When you create a new post and check the database the value isn't stored either in the postmeta table (check screenshot).

I created a test document a few minutes ago with id: 11834, as you can see in the screenshot the value isn't stored.

#1269061

Minesh
Supporter

Languages: English (English )

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

Ok - I see the relationship is stored within the database table "toolset_associations".

Please check the following screenshot:
=> hidden link

#1269065

I don't care where it is being stored 😉 the get_post_meta isn't working anymore after the upgrade. It should work as you guys state:

https://toolset.com/forums/topic/how-do-access-the-data-stored-for-a-entry-in-a-post-reference-field-using-php/

#1269067

Minesh
Supporter

Languages: English (English )

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

I understand. This looks like our Devs may have changed how post reference field is stored internally.

You need to change the get_post_meta with the Types post-relationship API function. Can you tell me where exactly you are using the get_post_meta() function?

#1269113

My issue is resolved now. Thank you! we found this https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts which helped us in changing the wp_query seems we have to read changelogs 😉

Thanks have a nice weekend!