Site icon Hip-Hop Website Design and Development

Select input in metabox not updated

I try to figure it out why my select input did not update the value.

I have placed the select input in the header of a metabox, the same what Woocommerce did with the producttype selector.

add_meta_box( 'catalog-item', metabox_header_details_callback(), 'catalog_details_callback', 'catalog', 'advanced' );

function metabox_header_details_callback(){
    ob_start();
    require_once(TEMPROOTPATHPRI . '/inc/admin/callbacks/metaboxes/cpt/catalog-details_header.php');
    return ob_get_clean();
}

the required file looks like this

<select class="catalog-item-type" name="catalog_item_type" id="catalog_item_type">
    <optgroup label="Onderdeeltype">
        <option value="test">test</option>
        <option value="valve">Klep</option>
        <option value="piston">Zuiger</option>
    </optgroup>
</select>

<?php
add_action('save_post', function($post_id){
    if(isset($_POST['catalog_item_type'])){
        update_post_meta($post_id, 'catalog_item_type', $_POST['catalog_item_type']);
    }
?>

If I update the post he put always the value of the first option into the database.

If I put my code into the main callback of the metabox the data is saves correctly.
But I want the selector in the header is there a other way to do this?