'Why is there a string saved in my serialized array?
Below is how I serialize my array.
$featured_image_id = $arg['thumbnail_id'];
$data = serialize( array( $featured_image_id ) );
update_post_meta( $arg['post_id'], 'images', $data );
What I get in my db table is s:17:"a:1:{i:0;i:1955;}"; with a string in front.
How do I remove the string? I just need "a:1:{i:0;i:1955;}"
Solution 1:[1]
Ok, I fixed it.
I don't need to serialize the array. It will be serialized by update_post_meta function as according to https://developer.wordpress.org/reference/functions/update_post_meta/
WordPress doc is always not clear. It should change from saying "Metadata value. Must be serializable if non-scalar." to "Metadata value. Value will be automatically serialized if non-scalar." PHP doc is still the best.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | codanad376 |
