Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using wp all import to load in datafeeds but when i set a custom field (thats needed for the theme) it keeps modding it before it stores it

when I put this in the field : a:7:{test}

it saves it as s:10"a:7:{test}"

Even when I update thru update_post_meta and set it there manually it adds the s:10...

How can I fix this, do I have to encase the string somehow? The custom field is same for each post is there some other way I can set it for each post in the php of the feeder?

EDIT:

update_post_meta($pid,'_attributes','a:7:{test}');  

in php will fill the field with s:10:"a:7:{test}" insteed of just a:7:{test}

share|improve this question
add comment

2 Answers

update_post_meta is maybe_serialising.

And in this case is storing it as a serialised string

The string your passing isn't a correctly serialised array.

If you pass it the raw array it will self convert it to the correct serialised string.

The correct string is a:1:{i:0;s:4:"test"}, passing that shouldn't serialise but probably will. You are betted off passing in the array as an array

If you want to store an already serialised object, direct Database write.

share|improve this answer
add comment

When updating metadata, maybe_serialize() is applied (see source). This serialises any array/string but will also double serialize serialized data.

You should just pass an actual array.

If you have a serialised array which you want to unserialize, you can use maybe_unserialize(). That said, as has been pointed out, a:7:{test} is not a correctly serialised array.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.