首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法保存来自metabox插件的自定义metabox数据

无法保存来自metabox插件的自定义metabox数据
EN

Stack Overflow用户
提问于 2014-07-04 15:44:42
回答 1查看 107关注 0票数 0

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

代码语言:javascript
复制
 $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>';
                }   

现在,在save函数中,我有以下代码。我只能保存pax-price,而不能保存与pax-price一起的日期。需要帮助,提前感谢您的帮助

代码语言:javascript
复制
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 );
        }
EN

回答 1

Stack Overflow用户

发布于 2014-07-05 01:12:45

不管怎样,我得到了解决方案。我在显示方式上犯了一个错误,以防有人需要一种方法:

$tour_rates = get_post_meta( $post->ID,$id,true )?maybe_unserialize(get_post_meta( $post->ID,$id,true )):false;

代码语言:javascript
复制
    $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>';
        }

现在,save函数保持不变

代码语言:javascript
复制
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 );

        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24569146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档