samedi 30 janvier 2021

saving multiple values in select not working PHP

I am having trouble to save the option values in a select box?, it only save one option, adding a [] after the name in the selectbox (array) the whole function breaks and saves nothing

Here's my code:

 function wp_custom_client($post)
{
    $args = array(
        'role' => 'customer',
        'order_by' => 'user_nickname',
    );
    $users = get_users($args);

    $customer = get_post_meta($post->ID, 'wp_custom_attachment_user', true);


    print '<select id="wp_custom_attachment_user" name="wp_custom_attachment_user" style="width:250px; height: 150px;" multiple>';
    print '<option value="" disabled selected>' . __('Kies een klant') . '</option>';
    foreach ($users as $user) {
        $selected = ($user->ID == $customer) ? 'selected' : '';
        print '<option value="' . $user->ID . '" ' . $selected . '>' . $user->display_name . '</option>';
    }
    print '</select>';
    print '<p>Hou Ctrl (Windows) of Command (Mac) ingedrukt om meerdere opties te selecteren.</p>';

}

And the saving code:

  /* Customer */
    if (isset($_POST['wp_custom_attachment_user'])) {
        update_post_meta($id, 'wp_custom_attachment_user', $_POST['wp_custom_attachment_user']);

    }

Anyone can help please?? Much appreciaded




Aucun commentaire:

Enregistrer un commentaire