Skip Navigation

[Resolved] combining user fields and post fields on the same custom post

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.

Our next available supporter will start replying to tickets in about 1.40 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#2660109
user-field.jpg

Tell us what you are trying to do?
My user creates a new post (front end) - they make some edits and through a cred form they save those edits to the new post. I need to capture a piece of user data to that new post.
I have a custom post that has custom post fields. I need to add a custom user field that I then use a cred form on the front end to update the custom user field default on the individual post.
I do not see any way to include a user field into my custom post and then update it.
Is there any documentation that you are following?

Is there a similar example that we can see?
Image attached
What is the link to your site?

#2661005

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

By default, the user fields can't be used in the post forms, but there is a workaround that you can use.

In your post form, you can include a generic field with the same value options, as the user field.
( ref: https://toolset.com/lesson-placement/lesson-placements-1621521-1620257/ )

After that, you can use a custom function attached to the 'cred_save_data' hook, that executes, when the form is submitted, to save/update that selected generic field's value, as the user field's value:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/update_user_meta/

You'll find example code snippets for a similar requirement in the following support threads:
https://toolset.com/forums/topic/cant-save-generic-field-data-to-custom-user-meta-field/
https://toolset.com/forums/topic/include-user-meta-fields/

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#2661013

Hi. Thanks for your response.
Can I confirm (as I am not a coder). Your documentation on generic field says it 'does not' add it to the post which is what i need. your other links says that it can be added to a user ID meta data but this is not what I need.
Are your other code recommendations going to add the generic field data to the post if I get it coded for me in the way you suggest?

#2661563

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Your understanding is correct and by default, the generic field values are not saved in the database.

But the custom code approach that I suggested would execute the custom function every time the form will be submitted successfully. That custom function will fetch the value of the generic field and save it as the target user field's value.

Using those example forum threads, you'll be able to adjust the code snippet as per your website. You'll only need to adjust the form ID and the target user field's slug, in the code snippet.

To hire a professional to help you with the code customization, we have a list of contractors at:
https://toolset.com/contractors/

grahamA confirmed that the issue was resolved on 2023-11-07 15:57:58.
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.