Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter au.petrone

    (@aupetrone)

    new code

    <?php
    
    add_action('wp_insert_post', 'register_ForumCustom');
    
    function register_ForumCustom($post_id){
    
    	$post = get_post($post_id);
    
    	$post_status = $post->post_status;
    
    	if($post_status=="auto-draft" || $post_status=="draft"){
    		return;
    	}
    	// Create post object
    	$my_new_post = array(
    	  'post_title'    => 'Forum di'.$post->post_title,
    	  'post_content'  => '',
    	  'post_status'   => 'publish',
    	  'post_author'   => 1,
    	  'post_type' => 'forum'
    	);
    
    	// Insert the post into the database
    	$new_forum_id = wp_insert_post( $my_new_post );
    
    	//OK, maybe is here that the loop starts, but i know that the problem is because there is another "wp_insert_post". I can solve this, but i don't understand the other problem!
    	remove_action('wp_insert_post', 'register_ForumCustom');
    	update_post_meta($post_id, "forum_id", $new_forum_id);
    	add_action('wp_insert_post', 'register_ForumCustom');
    
    }
    
    ?>
    Thread Starter au.petrone

    (@aupetrone)

    Thank you! Solved going in Settings!

    Thread Starter au.petrone

    (@aupetrone)

    I’m trying to save some data but i can’t. The problem is that the data saved is not that i expect but is an empty array.

    This is the code…i’m going mad!

    <?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"));
    Thread Starter au.petrone

    (@aupetrone)

    Ok, now is correct, i don’t see the error anymore. But it still doesn’t save my data.

    Here is the new code

    <?php
    /*
    Plugin Name: nw_Page_Gallery
    
    */
    
    class NW_mb{
    
    	var $post_meta = array("image1","image2");
    
    	var $boxes = array();
    
    	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");
    
    		print_r($post->ID);
    
    		?>
    
    		<label>Indirizzo immagine</label>
    		<input type="text" id="nw_image1" name="nw_image1" value="<?php echo $this->post_meta[0] ?>" />
    
    		<label>Indirizzo immagine</label>
    		<input type="text" id="nw_image2" name="nw_image2" value="<?php echo $this->post_meta[1] ?>" />
    
    		<label>Indirizzo immagine</label>
    		<input type="text" id="nw_image3" name="nw_image3" value="<?php echo $this->post_meta[2] ?>" />
    
    		<label>Indirizzo immagine</label>
    		<input type="text" id="nw_image4" name="nw_image4" value="<?php echo $this->post_meta[3] ?>" />
    
    		<label>Indirizzo immagine</label>
    		<input type="text" id="nw_image5" name="nw_image5" value="<?php echo $this->post_meta[4] ?>" />
    
    		<?
    
    	}
    
    	public function save_Box($id){
    
    		update_post_meta($id, 'nw_meta_boxes', array(
    			isset($_POST['nw_image1']),
    			isset($_POST['nw_image2']),
    			isset($_POST['nw_image3']),
    			isset($_POST['nw_image4']),
    			isset($_POST['nw_image5'])
    		));
    
    	}
    
    }
    
    add_action("add_meta_boxes", function(){
    
    	$NW_mb_istance = new NW_mb;
    	$NW_mb_istance->add_Box();
    });
    
    add_action("save_post", function(){
    	NW_mb::save_Box();
    });
Viewing 4 replies - 1 through 4 (of 4 total)