0

I have the following select values:

<select name="vibe_quiz_tags[]" id="vibe_quiz_tags" multiple="" class="chzn-select chosen select2-hidden-accessible" tabindex="-1" aria-hidden="true">
   <option value="">Select Taxonomy</option>
   <option value="4">Test1</option>
   <option value="5">Test2</option>
</select>

I post these variables and serialize them with the following code:

$categories = serialize($_POST["vibe_quiz_tags"]);
echo $categories;

I then get the following code when it is output:
a:2:{i:0;s:1:"4";i:1;s:1:"5";}

I update the post meta with the following:

update_post_meta($quiz_id, 'vibe_quiz_tags', $categories);

When it gets inserted into the database it adds an s:30 at the beginning. Here is what is actually stored in the database:
s:30:"a:2:{i:0;s:1:"4";i:1;s:1:"5";}";

Why is wordpress adding the s:30 at the beginning?

2

This happens when an already serialized string get serialize again.

Replace

$categories = serialize($_POST["vibe_quiz_tags"]);

with

$categories = $_POST["vibe_quiz_tags"];

EDIT:

As mentioned by czerspalace in the comments, the Function Reference for update_post_meta states that "this should be raw as opposed to sanitized for database queries".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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