Problem:
How could I update a Post Excerpt when submitting a Toolset Form, using the value of a Custom Field set in the Toolset Form?
Solution:
Excerpts are built using the Post Body and are part of the Post, hence you will need to manipulate that content with wp_update_post(), which is a WordPress API Function.
To do this when submitting a Toolset Form, you can update your post within a cred_save_data() hook, where you should define a $variable with the content of the Custom Field from which you want to pull the data to update the Excerpt with.
TIPP:
You can get that Field's contents either from $_POST or, you can get it with WordPress API get_post_meta()
Then, the $variable holding the value set in the Custom Field on the Form, can be used to update the Post Excerpt using wp_update_post() within the Toolset Forms Hook
Here is an example of such custom code that takes a custom field value and updates the Post Title with it:
https://pastebin.com/2BTbVbcs
To use it for Post Excerpt, you'd just target post_excerpt, instead of post_title, which is used in the example linked
Relevant Documentation:
https://developer.wordpress.org/reference/functions/get_post_meta/
https://www.php.net/manual/en/reserved.variables.post.php
https://developer.wordpress.org/reference/functions/wp_update_post/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
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 4 years, 8 months ago.
Assisted by: Beda.