我是php和wordpress的新手,但有编程知识。我试图通过创建一个新的自定义元对象来将这些元对象的数据保存在元对象插件中。这是我的代码
$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一起的日期。需要帮助,提前感谢您的帮助
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 );
}发布于 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;
$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> </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函数保持不变
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 );
}https://stackoverflow.com/questions/24569146
复制相似问题