Currently you are passing on this value:
'post_category' => array('3,4,5') // This is a single string
While you should be doing this:
'post_category' => array(3,4,5) // Three separate values
Don’t forget to sanitize the POST values neither:
// Initialize categories
$post_category = array();
// Prevent "undefined variable" error notices
if (isset($_POST['vtype']))
{
// Loop over selected categories
foreach ((array) $_POST['vtype'] as $vtype)
{
// Validate vtype (only numbers allowed)
if (ctype_digit((string) $vtype))
{
// Add category
$post_category[] = (int) $vtype;
}
}
}
// Save the post with $post_category in database as you did before...
You can shorten this whole block to a oneliner as well, if you like. Just for fun:
$post_category = (isset($_POST['vtype'])) ? array_filter((array) $_POST['vtype'], 'ctype_digit') : array();