• I encounter a weird bug with my custom meta boxes.

    Every other custom-field (using more-fields and more-types plugins) below my meta-box are empty when editing a page.

    Ive checked everything and it seems that metadata isnt gone, everything still shows up correctly in front-end as well in DB, but in backend it seems that my meta-box is disrupting loading of everything else.

    I have 9 custom fields in 4 containers when i drag-n-drop my metabox into first position, all other boxes below are empty while editing and if update button is hitted, well data is lost.

    can ANYONE see what am i missing out in my code ?
    quick idea is that i use custom post type where i have entire crew-team. but for each other custom post type i need to add someone in the crew as contact-person. but this contact dropdown screws everything else up ??

    OK – Here is my metabox at the end and all works
    Error – Here is my metabox above some other boxes and those end up empty

    add_action('admin_menu', 'add_contact_as_list', 16);
    	add_action('save_post', 'contactlist_save_handler');
    
    	function add_contact_as_list() {
    		if ( function_exists('add_meta_box') ) {
    			/*add_meta_box(
    				'myplugin_sectionid',
    				__( 'Kontaktlista', 'myplugin_textdomain' ),
    				'myplugin_inner_custom_box',
    				'post'
    			);*/
    			add_meta_box(
    				'myplugin_sectionid',
    				__( 'Kontaktlista', 'myplugin_textdomain' ),
    				'myplugin_inner_custom_box',
    				'page'
    			);
    		}
    	}
    
    	function myplugin_inner_custom_box() {
    
    		$editPostID = $_REQUEST['post'];
    		//wp_nonce_field( plugin_basename(__FILE__), 'myplugin_noncename' );
    
    		$args = array(
    			'post_type' => array( 'Medarbetare' ),
    			'orderby' => 'rand'
    		);
    
            query_posts( $args );
    
    		echo '<p><label for="contactlist_selected_person_id">';
    		  	 _e("V?lj kontakt vars info ska publiceras", 'myplugin_textdomain' );
    		echo '</label> </p>';
    		$var;
    
    		$my_meta = get_post_custom($editPostID);
    		$selectedID = $my_meta['contactlist_selected_person_id'][0];
    		$sel = 0;
    		echo '<p><select id="contactlist_selected_person_id" name="contactlist_selected_person_id" >';
    			while ( have_posts() ) : the_post();
    				$id = get_the_ID();
    				if($selectedID == $id){
    					echo '<option value="'.$id.'" SELECTED >'.get_post($id)->post_title.'</option>';
    					$sel = 1;
    				}else{
    					echo '<option value="'.$id.'" >'.get_post($id)->post_title.'</option>';
    				}
    			endwhile;
    			if($sel == 0){
    				echo '<option value="Ingen" SELECTED>Ingen</option>';
    			}else{
    				echo '<option value="Ingen">Ingen</option>';
    			}
    		echo '</select></p>';
    		wp_reset_query();
    	}
    
    	function contactlist_save_handler( $post_id ) {
    
    		  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) ) )
    			  return $post_id;
    
    		  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
    			  return $post_id;
    
    		  if ( 'page' == $_POST['post_type'] )
    		  {
    			if ( !current_user_can( 'edit_page', $post_id ) )
    				return $post_id;
    		  }
    		  else
    		  {
    			if ( !current_user_can( 'edit_post', $post_id ) )
    				return $post_id;
    		  }
    
    		  $mydata = $_POST['contactlist_selected_person_id'];
    
    		add_post_meta($post_id, 'contactlist_selected_person_id', $mydata, true) or update_post_meta($post_id, 'contactlist_selected_person_id', $mydata);
    		return $mydata;
    	}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Metaboxes are empty’ is closed to new replies.