无法从metabox插件保存自定义metabox数据


Unable to save custom metabox data from metabox plugin

我对php和wordpress很陌生,但有编程知识。我试图通过创建一个新的自定义metabox来保存metabox插件中这些metabox的数据。这是我的代码

 $tour_rates = get_post_meta( $post->ID, $id, true ) ? maybe_unserialize(get_post_meta( $post->ID, $id, true )) : false;
    if ($tour_rates){
                foreach ( $tour_rates as $options => $option ) {
                    $key = 1        
                    $html .= '<tr class="rate-line">';
                    $html .= '<td>';
                    $html .= '<span>Opt ' . ($options+1) . '</span>';
                    $html .= '<input type="hidden" name="' . $id . '[]" class="rwmb-text" size="30" value="">';
                    $html .= '</td>';                       
                    $html .= '<td><input type="text" name="pax_date_'.$key.'[]" class="rwmb-date" size="3" value="'.$option[$key-1].'"></td>';
                    $html .= '<td><input type="text" name="pax_price_'.$key.'[]" class="pax-price" size="3" value="'.$option[$key-1].'"></td>';
                    $html .= '</tr>';
                }   

现在在保存函数我有这个代码。我只能保存pax-price,而不能保存日期和pax-price。需要帮助,提前感谢你所有的帮助

static function save( $new, $old, $post_id, $field )
        {
            $name = $field['id'];
            $tour_rates = array();
            foreach ( $_POST[$name] as $k => $v ) {
                $tour_rates[$k] = array(
                    $_POST['pax_price_1'][$k],
                    $_POST['pax_date_1'][$k],
                );
            }
            $new = maybe_serialize( $tour_rates );
            update_post_meta( $post_id, $name, $new );
        }

无论如何我得到了解决方案。我在显示的方式上犯了一个错误,只是以防有人需要一个方法:

$tour_rates = get_post_meta($post->ID, $ ID, true) ?maybe_unserialize(get_post_meta($post->ID, $ ID, true)): false;
    $html = '<div id="tour-rates-info">';
        $html .= '<div class="inside">';
        $html .= '<div class="rwmb-field">';
        $html .= '<div class="rwmb-input">';
        $html .= '<table>';
        $html .= '<tr>';
        $html .= '<th>&nbsp;</th>'; 
            $html .= '<th>'."Departure Date".'</th>';
            $html .= '<th>'."Price".'</th>';
        $html .= '</tr>';
    if ($tour_rates){
        foreach ( $tour_rates as $k => $v ) {       
            $key = 1;
            $html .= '<tr class="rate-line">';
            $html .= '<td>';
            $html .= '<span>Opt ' . ($k+1) . '</span>';
            $html .= '<input type="hidden" name="' . $id . '[]" class="rwmb-text" size="30" value="">';
            $html .= '</td>';               
            $html .= '<td><input type="text" name="pax_date_'.$key.'[]" class="rwmb-date" size="9" value="'.$v[0].'"></td>';
                $html .= '<td><input type="text" name="pax_price_'.$key.'[]" class="pax-price" size="9" value="'.$v[1].'"></td>';

            $html .= '</tr>';
        }

现在保存函数保持不变

static function save( $new, $old, $post_id, $field )
        {
            $name = $field['id'];
            $tour_rates = array();
            $tour_rate = array();
            foreach ( $_POST[$name] as $k => $v ) {
                $tour_rates[$k] = array(
                    $_POST['pax_date_1'][$k],
                    $_POST['pax_price_1'][$k],
                );
            }
            echo $tour_rates;
            $new = maybe_serialize( $tour_rates );
            update_post_meta( $post_id, $name, $new );
        }