0

I'm developing a wordpress theme which uses GBS. In the database field values are stored like this:

a:1:{i:0;s:7:"Virtual";}

Which clearly uses serialize, However when I store a meta value and use php to serialize I get this:

s:24:"a:1:{i:0;s:7:"Virtual";}";

Is there any way to not get the string count of the entire array? Here's the code I used:

update_post_meta( $post_id, 'location', serialize(array('Virtual')) );

3 Answers 3

1

It looks like it's being double serialized, meaning update_post_meta serializes it already. Try it without your explicit call to serialize:

update_post_meta( $post_id, 'location', array('Virtual'));
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I was just being dopey I guess, works fine now. Thanks!
0

update_post_meta seems to serialize whatever you send (a string of a serialized array in this time). Did you tried to change the thirs argument to just array('Virtual');??

Comments

0

You can explode by : slice off the first two bits of the array and then implode back on ":" like so

$str = 's:24:"a:1:{i:0;s:7:"Virtual";}";';
$expected = '"a:1:{i:0;s:7:"Virtual";}";';
$bitsOfSerial = explode(":", $str);
$noStringLengthBits = array_slice($bitsOfSerial, 2);
$actual = implode(":", $noStringLengthBits);
assert($expected === $actual);
echo $actual;

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.