Skip Navigation

[Resolved] Custom post reference field not updating in the database but showing in wp admin

This support ticket is created 6 years, 3 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)

Author
Posts
#1133765
step4.PNG
step3.PNG
step2.PNG
step1.PNG

I am trying to:
I have a front end form that creates a post in a custom post type all created by toolset. The field that is not working on the post reference field to another post which only returns post id in the db. it was working fine in the past but suddenly, i am seeing this weird issue.

When i enter the form from the front end to update custom field reference and hit submit the database is not updated with that custom field. but i am able to see the field in the wp-admin side.
I am trying to access that field via php by $recievingcounty = get_post_meta( $currentpostid );
var_dump($recievingcounty);
and getting null.

When i go back in the wp admin, the field is populated properly. Now if i update the post by hitting update in the backend the database gets updated and everything starts to work again.

Link to a page where the issue can be seen:

I expected to see:

Instead, I got:

#1133782
custom field phptp.PNG

attaching screenshot of the custom field that i am having issue with..

Also php_value max_input_vars is 10000 from 1000. Doing so didnt help.

#1134303

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - do you mean that you want to display the post reference field value on front-end?

#1134304

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - do you mean that you want to display the post reference field value on front-end?

#1134417

I have the field on the front end, if you read thru my description properly and look at thee images step by step you can see what issue i am having. I have the field working but there seems to be a bug that from front end is not updating database with the custom field.

#1134819

Upon doing further research on this issue. I found out that post reference custom field is not being saved in the post_meta table from the front end form. When i go in the admin panel and update the post only then post_meta table updates.

#1134865

Minesh
Supporter

Languages: English (English )

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

Ok - so what if you try to use the Forms hook cred_save_data to save the field value.

Please try to add following code to your current theme's functions.php file.

add_action('cred_save_data', 'func_update_post_reference_field',10,2);
function func_update_post_reference_field($post_id, $form_data){
  // if a specific form
  if ($form_data['id']==9999) {
     update_post_meta($post_id, 'wpcf-receiving-countynew', $POST['wpcf-receiving-countynew']);
  }
}

Where:
- Replace 9999 with your original form ID

If the above code does not help, please share problem URL where you added the form with access details so I can fix it for you.

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