4 Replies to “Adding Meta Boxes to Your Post Screen”

  1. This is a great article, thanks so much. I’ve read a few tutorials about metaboxes, but yours is the one I’m pinching code from.

    Can I ask why the line:
    if( $post->post_type == 'revision' ) return; // WE DON'T WANT IT STORED TWICE
    is in the foreach loop in the save routine? Surely if the post type is “revision”, this will be true for all the variables, so why check more than once?

    Also, in the same loop, why delete the metadata if the new value is blank? The previous lines would have added or updated the metadata with the blank value.

    1. Thanks for taking the time to comment, I appreciate the positive feedback. I’ll tell ya what, I’m no coder. I lift things from all over the place, and test it a bunch and if it’s good, use it and share. So I probably lifted the save routine from somewhere, or built it from a couple other people’s examples. It worked perfectly for me, so I left it as I have it now. But if I have unnecessary stuff in there that’s good to know. Just leave it out if it’s not needed. I’ll try to do some further testing and report back soon. I update my posts on here constantly if I find better or neater ways to do things.

  2. How am i gonna save looping fields from java/jquery?
    i can’t find solutions… help please :s

    <script type="text/javascript">
    function add() {
    	var count = 1;
    
    	for(var i=0; i<count; i++) {
    		var input = document.createElement('INPUT')
    		input.name='prod_color[]'
    		input.style.width='80px'
    		input.style.padding='5px'
    		input.style.textAlign='center'
    		input.style.height='30px'
    		input.style.marginRight='4px'
    		input.value='<?php $prod_color ?>'
    		// bind jscolor
    		var col = new jscolor.color(input)
    
    		document.getElementById('ColorBoxes').appendChild(input);
    	}
    }
    		$prod_color = get_post_meta($post->ID, 'prod_color', true);
    
    		foreach ($_POST['color'] as $prod_color) {
    		// saving colors
    		$catalog_meta['color'] = $prod_color;
    		}
    

    i can’t save the fields… :’s help please..

Leave a Reply