• Hello everybody,
    I try to custom my wordpress admin by adding some meta boxes.
    But when there is more than one box on a page only one box is saved.
    Do you know why?

    Thanks

    $page_data = get_page( $_GET['post'] );
    	$parent_page = $page_data->post_parent;	
    
    		///// CHAPEAU
    	add_action( 'add_meta_boxes', 'chapeau_add_custom_box' );
    	add_action( 'save_post', 'chapeau_save_postdata' );
    	if($_GET['post'] == 6 OR $_GET['post'] == 303){
    		///// CHIFFRE A PROPOS DE MGA
    		add_action( 'add_meta_boxes', 'nb_mga_add_custom_box');
    		add_action( 'save_post', 'nb_mga_save_postdata' );
    	}if($parent_page == 60 OR $parent_page == 352){
    		///// CATéGORIE DANS LES PAGES éTUDES
    		add_action( 'add_meta_boxes', 'myplugin_add_custom_box' );
    		add_action( 'save_post', 'myplugin_save_postdata' );
    	}
    
    	///// CATéGORIE DANS LES PAGES éTUDES
    
    	/* Adds a box to the main column on the Post and Page edit screens */
    	function myplugin_add_custom_box() {
    		add_meta_box('myplugin_sectionid3', __( 'Cat&eacutegorie', 'myplugin_textdomain' ), 'myplugin_inner_custom_box','page');
    	}
    
    	/* Prints the box content */
    	function myplugin_inner_custom_box( $post ) {
    
    	  // Use nonce for verification
    	  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
    
    	  // The actual fields for data entry
    
    	  echo "<form name='tag'>";
    	  echo "<label for='tag'>Cat&eacutegorie &nbsp;</label>";
    	  echo "<input type='text' id='fond1' name='tag' style='width:70%;' value='".get_post_meta($post->ID, 'tag', true)."'/>";
    	  echo "</form>";
    	}
    
    	/* When the post is saved, saves our custom data */
    	function myplugin_save_postdata( $post_id ) {
    	  // verify if this is an auto save routine.
    	  // If it is our form has not been submitted, so we dont want to do anything
    	  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		  return;
    
    	  // verify this came from the our screen and with proper authorization,
    	  // because save_post can be triggered at other times
    
    	  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )
    		  return;
    
    	  // Check permissions
    	  if ( 'page' == $_POST['post_type'] )
    	  {
    		if ( !current_user_can( 'edit_page', $post_id ) )
    			return;
    	  }
    	  else
    	  {
    		if ( !current_user_can( 'edit_post', $post_id ) )
    			return;
    	  }
    
    	  // OK, we're authenticated: we need to find and save the data
    
    	  $mydata = $_POST['tag'];
    
    	  // Do something with $mydata
    	  // probably using add_post_meta(), update_post_meta(), or
    	  // a custom table (see Further Reading section below)
    	  update_post_meta(get_the_ID(), tag, $mydata); 
    
    	}
    
    	///// CHAPEAU
    
    	/* Adds a box to the main column on the Post and Page edit screens */
    	function chapeau_add_custom_box() {
    		add_meta_box('myplugin_sectionid', __( 'Chapeau', 'myplugin_textdomain' ), 'chapeau_inner_custom_box','page');
    	}
    
    	/* Prints the box content */
    	function chapeau_inner_custom_box( $post ) {
    
    	  // Use nonce for verification
    	  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
    
    	  // The actual fields for data entry
    
    	  echo "<form name='chapeau'>";
    	  echo "<textarea style='width:100%' rows='6' id='chapeau' name='chapeau'>".get_post_meta($post->ID, 'chapeau', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "</form>";
    	}
    
    	/* When the post is saved, saves our custom data */
    	function chapeau_save_postdata( $post_id ) {
    	  // verify if this is an auto save routine.
    	  // If it is our form has not been submitted, so we dont want to do anything
    	  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		  return;
    
    	  // verify this came from the our screen and with proper authorization,
    	  // because save_post can be triggered at other times
    
    	  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )
    		  return;
    
    	  // Check permissions
    	  if ( 'page' == $_POST['post_type'] )
    	  {
    		if ( !current_user_can( 'edit_page', $post_id ) )
    			return;
    	  }
    	  else
    	  {
    		if ( !current_user_can( 'edit_post', $post_id ) )
    			return;
    	  }
    
    	  // OK, we're authenticated: we need to find and save the data
    
    	  $chapeau = $_POST['chapeau'];
    
    	  // Do something with $mydata
    	  // probably using add_post_meta(), update_post_meta(), or
    	  // a custom table (see Further Reading section below)
    	  update_post_meta(get_the_ID(), 'chapeau', $chapeau);
    	}
    
    	///// CHIFFRE A PROPOS DE MGA
    
    	/* Adds a box to the main column on the Post and Page edit screens */
    	function nb_mga_add_custom_box() {
    		add_meta_box('myplugin_sectionid2', __( 'Donn&eacute;es illustr&eacute;es', 'myplugin_textdomain' ), 'nb_mga_inner_custom_box','page');
    	}
    
    	/* Prints the box content */
    	function nb_mga_inner_custom_box( $post ) {
    
    	  // Use nonce for verification
    	  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
    
    	  // The actual fields for data entry
    
    	  echo "<form name='donnees'>";
    	  echo "<label for='donnee1'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb1.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee1' name='donnee1'>".get_post_meta($post->ID, 'donnee1', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "<label for='donnee2'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb2.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee2' name='donnee2'>".get_post_meta($post->ID, 'donnee2', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "<label for='donnee3'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb3.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee3' name='donnee3'>".get_post_meta($post->ID, 'donnee3', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "<label for='donnee4'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb4.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee4' name='donnee4'>".get_post_meta($post->ID, 'donnee4', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "<label for='donnee5'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb5.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee5' name='donnee5'>".get_post_meta($post->ID, 'donnee5', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "<label for='donnee6'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb6.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee6' name='donnee6'>".get_post_meta($post->ID, 'donnee6', true)."</textarea>";
    	   echo "<br /><br />";
    	  echo "<label for='donnee7'><img style='background-color:#484848;' src='".get_bloginfo( 'template_url' )."/img/nb7.png' alt='#' /></label>";
    	  echo "<textarea cols='60' rows='6' id='donnee7' name='donnee7'>".get_post_meta($post->ID, 'donnee7', true)."</textarea>";
    	  echo "</form>";
    	}
    
    	/* When the post is saved, saves our custom data */
    	function nb_mga_save_postdata( $post_id ) {
    	   // verify if this is an auto save routine.
    	  // If it is our form has not been submitted, so we dont want to do anything
    	  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		  return;
    
    	  // verify this came from the our screen and with proper authorization,
    	  // because save_post can be triggered at other times
    
    	  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )
    		  return;
    
    	  // Check permissions
    	  if ( 'page' == $_POST['post_type'] )
    	  {
    		if ( !current_user_can( 'edit_page', $post_id ) )
    			return;
    	  }
    	  else
    	  {
    		if ( !current_user_can( 'edit_post', $post_id ) )
    			return;
    	  }
    
    	  // OK, we're authenticated: we need to find and save the data
    
    	  $mydata1 = $_POST['donnee1'];
    	  $mydata2 = $_POST['donnee2'];
    	  $mydata3 = $_POST['donnee3'];
    	  $mydata4 = $_POST['donnee4'];
    	  $mydata5 = $_POST['donnee5'];
    	  $mydata6 = $_POST['donnee6'];
    	  $mydata7 = $_POST['donnee7'];
    
    	  // Do something with $mydata
    	  // probably using add_post_meta(), update_post_meta(), or
    	  // a custom table (see Further Reading section below)
    	  update_post_meta(get_the_ID(), 'donnee1', $mydata1);
    	  update_post_meta(get_the_ID(), 'donnee2', $mydata2);
    	  update_post_meta(get_the_ID(), 'donnee3', $mydata3);
    	  update_post_meta(get_the_ID(), 'donnee4', $mydata4);
    	  update_post_meta(get_the_ID(), 'donnee5', $mydata5);
    	  update_post_meta(get_the_ID(), 'donnee6', $mydata6);
    	  update_post_meta(get_the_ID(), 'donnee7', $mydata7);
    	}
    
    ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Problem with multiple add_meta_boxes and save_post’ is closed to new replies.