• I’m trying to save a multiple select of categories in the database for a plugin.
    I’m using this Code to display the multiple select:

    $categories_list = wp_dropdown_categories( array( 'echo' => 0 ) );
     $categories_list = str_replace( "name='cat' id=", "name='optionName[]' multiple='multiple' style=\"width:100%\" id=", $categories_list );
     echo $categories_list;

    And this code for saving

    $nabanner_placement_CONTENT_ROLLOVER_new = sanitize_text_field( $_POST['nabanner_placement_CONTENT_ROLLOVER'] );
    if (preg_match('/(.*)/', $nabanner_placement_CONTENT_ROLLOVER_new)) {
    update_option('nabanner_placement_CONTENT_ROLLOVER', $nabanner_placement_CONTENT_ROLLOVER_new);}

    But instead of saving the selected values to the database it just saves the string “Array”.

The topic ‘Saving a multiple select in database’ is closed to new replies.