Problem:
How can I populate a Post Title with the value of a Custom field when saving a post?
Solution:
You need Custom Code.
If you use CRED; you can make usage of the CRED API cred_save_data:
https://toolset.com/documentation/user-guides/cred-api/#csd
You would use WordPress API to
get_post_meta()
the Field's Values and update the
post_title
with it.
An example:
http://pastebin.com/2BTbVbcs
Keep in mind that Repeating Fields are arrays and therfore you need a complex
foreach()
on them, to get out the single values.
If you do not use CRED, you can use full WordPress API, it will just be the same as if you would use native WordPress fields.
Then you need to hook into the
wp_update_post()
https://developer.wordpress.org/reference/functions/wp_update_post/
The only to keep in mind here too is that a Types repeating Field is an array, and therefore you need to
foreach()
over it's stored values.
http://php.net/manual/de/control-structures.foreach.php
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 nigelp 7 years, 7 months ago.
Assisted by: Beda.