Php 无法从metabox插件保存自定义metabox数据
我对php和wordpress很陌生,但有编程知识。 我试图通过创建一个新的自定义元盒,将这些元盒中的数据保存到metabox插件中。这是我的密码Php 无法从metabox插件保存自定义metabox数据,php,wordpress,post,meta-boxes,Php,Wordpress,Post,Meta Boxes,我对php和wordpress很陌生,但有编程知识。 我试图通过创建一个新的自定义元盒,将这些元盒中的数据保存到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 = 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>';
}
不管怎样,我找到了解决办法。我在展示的方式上犯了一个错误,以防万一有人需要一种方式: $tour\u rates=get\u post\u meta($post->ID,$ID,true)?可能是非序列化(获取帖子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\u post','callback function',1,2);
$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>';
}
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 );
}