I want to show default values for my fields, in case the field is not edited when saving the post (is empty).
I am editing and creating posts with CRED.
There are 2 possible ways to achieve this, one while adding the value of the Field, the other when displaying the field on the front end.
1. While adding the field value (edit the field on the front end thru a CRED form)
- create the custom fields and include them in the CRED Form
- pass a default value to them by using the "value" attribute
==> Since you had set a default value, the field will always show that default value if not changed
==> You can achieve the same by setting the default value in Toolset > Post Fields directly
Or, you can skip the above steps and update the Custom Field (if empty) with a custom hook to
update_post_meta()
with your default value, using the
cred_save_data()
filter
2. When outputting the field value on a post
- create the custom fields and include them in the CRED Form
- submit the cred form with eventually empty optional fields
- display the fields as used to, but wrap them in an HTML conditional
In the conditional, check if the field is empty to display your custom default text, or if it's not empty you can display the value of the field.
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 4 replies, has 2 voices.
Last updated by 6 years, 9 months ago.
Assisted by: Beda.