I need to do an import of an array of checkboxes, but there is a value that I don’t how it is determined.
The array is based on a user meta option that I created that shows a list of category checkbox options. It grabs all of the categories and creates a checkbox option that can be saved to a user’s profile. The categories have different levels (parent, child, or child-child).
This is part of the coding I used to create the user meta option:
$args = array( 'hide_empty' => 0, 'taxonomy'=> 'category');
$categories = get_categories($args);
if ($categories){
foreach ( $categories as $category ){
if(in_array($category->term_id,(array)$data)) {
$selected = 'checked="checked""';
} else {
$selected = '';
}
echo '<input name="user_cats[]" value="'.$category->term_id.'" '.$selected.' type="checkbox"/> '.$category->name.'<br/>';
}
}
After doing a test save of the some of the checkbox options, I examined the database value of the “user_cats” field, it gives me something like this:
a:2:{i:0;s:2:”20″;i:1;s:3:”343″;}
Now, I know what all but one of the variables stand for.
a = Total amount (quantity) of values/selections
i = Sequential number of the value/selection (*Starting with 0)
“X” = The number value within the parenthesis is the value
My question is, what is the s: value based on? The reason I ask is because Im compiling a csv file of 1,300 records to import and I dont know how the s: values are determined. I tried just give s: a constant value of 2, but after importing the values the options were not selected based on the arrays that were imported. That didn’t work.
So I have a feeling that the selecting of the correct options are based on the s: value. An alternative would be if Im able to import an array without that current syntax.
I spent a long time manually compiling the file with excel functions and tricks and this is the only road block. Any help with this would be a major savior.
That’s the php serialize format: