JustinasT
JustinasT

Reputation: 633

PHP serialize() format

The problem is with storing serialized Data in Wordpress database. What I'm trying to do: I'm trying to store ID's of images as serialized array:

$image_id_array = array(0=>1234, 1=>2345, 2=>3456);
$gallery_serialized = serialize($image_id_array);
update_post_meta($post_id, 'gallery', $gallery_serialized);

Result I need to be stored looks like this:

a:3:{i:0;i:1234;i:1;i:2345;i:2;i:3456;}

Result, that is actually stored:

s:41:"a:20:{i:0;i:1234;i:1;i:2345;i:2;i:3456;}";

How can I drop s: value and columns?

Upvotes: 0

Views: 118

Answers (1)

JustinasT
JustinasT

Reputation: 633

Seems that update_post_meta serializing data by itself. Solution:

update_post_meta($post_id, 'gallery', $image_id_array);

Thanks to @Neodan

Upvotes: 2

Related Questions