0

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?

3
  • 4
    Looks like you have multiple serialize() calls somewhere. The code you've provided gives what you want. Commented Mar 5, 2019 at 10:06
  • 2
    Do you try to skip your serialization? try: update_post_meta($post_id, 'gallery', $image_id_array); Commented Mar 5, 2019 at 10:08
  • You right, seems that update_post_meta serialize data by itself. Thank you! Commented Mar 5, 2019 at 10:12

1 Answer 1

2

Seems that update_post_meta serializing data by itself. Solution:

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

Thanks to @Neodan

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.