我正在尝试保存一些数据,但我不能。问题是保存的数据不是我所期望的,而是一个空数组。
这是代码。拜托,问题是什么?......我疯了!
PS:我正在学习PHP,所以这可能是一个愚蠢的问题......有没有办法在发送之前控制变量$ _POST?<?php
/*
Plugin Name: nw_Page_Gallery
*/
class NW_mb{
var $post_meta = array("image1","image2");
var $id;
public function __construct(){
}
public function add_Box(){
add_meta_box("nw_meta_box","Sfondo pagina",array($this, 'add_html'),"page");
}
public function add_Html($post){
$post_meta = get_post_meta($post->ID, "nw_meta_boxes");
$this->id = $post->ID;
print_r($post_meta);
?>
<label>Indirizzo immagine</label>
<input type="text" id="nw_image1" name="nw_image1" value="<?php echo $post_meta[0] ?>" />
<label>Indirizzo immagine</label>
<input type="text" id="nw_image2" name="nw_image2" value="<?php echo $post_meta[1] ?>" />
<label>Indirizzo immagine</label>
<input type="text" id="nw_image3" name="nw_image3" value="<?php echo $post_meta[2] ?>" />
<label>Indirizzo immagine</label>
<input type="text" id="nw_image4" name="nw_image4" value="<?php echo $post_meta[3] ?>" />
<label>Indirizzo immagine</label>
<input type="text" id="nw_image5" name="nw_image5" value="<?php echo $post_meta[4] ?>" />
<?
}
public function save_Box(){
$boxes = array(
isset($_POST['nw_image1']),
isset($_POST['nw_image2']),
isset($_POST['nw_image3']),
isset($_POST['nw_image4']),
isset($_POST['nw_image5'])
);
update_post_meta($this->id, 'nw_meta_boxes', $boxes);
}
}
add_action("add_meta_boxes", function(){
$NW_mb_istance = new NW_mb;
$NW_mb_istance->add_Box();
});
add_action("save_post", array($NW_mb_istance,"save_Box"));