Problem:
Client uses some custom code to duplicate posts, which works correctly except for checkboxes fields. How to handle duplicating checkboxes fields onto the new posts?
Solution:
Checkboxes fields are stored as serialized arrays in wp_postmeta, and there is an anomaly with WordPress in how the value is returned by get_post_meta, depending on whether you retrieve the value of the field directly (by specifying the key), where it is returned as an array, or whether you retrieve the value of all fields at once (by not specifying a key), where it is returned as a string.
I updated the code used by the client to use the function maybe_unserialize to update the value before saving the post meta on the new, duplicated, post, as shown below: https://toolset.com/forums/topic/retain-checkbox-and-relationship-value-when-duplicate-post-on-front-end/#post-948285
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 |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 1 reply, has 2 voices.
Last updated by 6 years, 3 months ago.
Assisted by: Nigel.