Skip Navigation

[Resolved] How to create custom fild with data from 3 custom fields?

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

Problem:
I want to populate one Custom Field with the value of several other Custom Fields when saving the post either in the backend or front end.
I know how to display values of the fields, I need to merge values when saving the post.

Solution:
This is not possible natively in Toolset, as it requires custom code.

You can either save the new Custom Values when editing the post in the backend by hooking the custom code to WordPress' action save_post(), or in a Toolset Form, to the action cred_save_data()

That custom code should get the values of all Custom Fields you want to use to populate the last, to be updated field.
Then concatenate them into a new $variable and with that variable, you can update the new post field.
For this you will use get_post_meta() and update_post_meta()

At Toolset Support however we cannot provide "ready to use" Custom Code snippets, according to our Support Policy: https://toolset.com/toolset-support-policy/,

Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/get_post_meta/
https://developer.wordpress.org/reference/functions/update_post_meta/
https://pastebin.com/u/bedas
Specially https://pastebin.com/2BTbVbcs, https://pastebin.com/A2UMXVUJ https://kb.onthegosystems.com/code-snippet/update-post-titlename-with-a-date-from-a-types-date-cf/

This support ticket is created 5 years, 6 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by PawelS4412 5 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#1242492

Tell us what you are trying to do?
I have filled in custom fields, and I need a new one which will automatically add text from CF1 | CF2 |CF3
Example:
CF1: pet
CF2: dog
CF3: brown

CF4: (new one that this ticket is about) should be: CF1 | CF2 | CF3
It should look like this: pet | dog | brown

How to creati CF4 like that?

Is there any documentation that you are following?
I was looking in documentary but didnt find answer

Is there a similar example that we can see?
dont know

What is the link to your site?
hidden link

#1242540

This is not possible natively in Toolset, as it requires custom code.

You can either save CF4 when editing the post in the backend by hooking the custom code to WordPress' action save_post(), or in a Toolset Form, to the action cred_save_data()
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

That custom code should get the values of all 3 previously filled CF's (CF1, CF2 and CF3), then concatenate them into a new $variable and with that variable you can update the new post field CF4. You will use get_post_meta() and update_post_meta() WordPress Core API for this:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://developer.wordpress.org/reference/functions/update_post_meta/

We cannot provide ready to use Custom Code snippets here in this Support forum according to our Support Policy https://toolset.com/toolset-support-policy/, however you might be able to find a good example on these 2 libraries:
https://pastebin.com/u/bedas
Specially https://pastebin.com/2BTbVbcs, https://pastebin.com/A2UMXVUJ, and hidden link

Please let me know if you need my help reviewing or improving the code.

#1242713

My issue is resolved now. Thank you!