0

I have followed the great answer by Jan Fabry in this question .

How to make multicheck for post/page meta box

this works great. My question though would be , what if someone WANTS a serialized value (array e.g. :"banana,apple,grapes" in ONE field ? ) and not separate values ?

It is strange how in all the tutorials, example, and classes, everyone ignores multiple selection (also in select list)

0

In his answer , Jan Fabry made a brilliant solution, but it saves the values one by one (for each his own field )

for your question, we need to "reverse" that , but it is actually easy .

BEFORE lines 409-413 , Jan Fabry made an if-else clause to seperate values into fields and save / update. we do not need it .

Instead , we take the already constructed array and save it as a whole. so you just need to add this instead of the whole bigger clause (and do not forget to drop the ELSE:

  if ( 'multicheck' == $field['type'] ) {
        // If it is a multicheck , implode the array and get a string...
    $new =implode(",", $new);
    } 

That´s all . and do not foget to thatnk JAN Fabry for it - not me :-)

Your Answer

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