データを保存しようとしていますが、できません。問題は、保存されたデータが期待どおりではなく、空の配列であることです。
これがコードです。どうか、何が問題なのですか?...私は怒っています!
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"));