WordPress.org

Ready to get started?Download WordPress

Forums

Custom Meta Box, working but not saving values (3 posts)

  1. mtedwards
    Member
    Posted 2 years ago #

    Hi Guys,

    I've been wrestling with this all day and I can't work out whats going wrong.

    I've got the custom meta boxes displaying; a text box and a drop down list, but I can't get them to save their values to the database.

    Am I missing something really simple?? Any guidance would be really appreciated.

    Here's my code:

    <?php
    function at_post_meta (){
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$at_slider_featured = $custom["at_slider_featured"][0];
    	$at_other_author = $custom["at_other_author"][0];
    	?>
    	<p>
    	<label>Featured Slider:</label><br/>
    	<select name="at_slider_featured">
    		<option value="false">False</option>
    		<option value="true">True</option>
    	</select>
    	</p>
    	<p>
    	<label>Other Author:</label><br/>
    	<input size="25" name="at_other_author" value="<?php echo $at_other_author; ?>" />
    	</p>
    <?php
    	}
    
    function add_at_post_box(){
    	add_meta_box(
    		"at_post_info",
    		"Post Details",
    		"at_post_meta",
    		"post",
    		"side",
    		"core"
    	);
    }
    
    function save_at_post_meta(){
    	global $post;
    	update_post_meta($post->ID, "at_slider_featured", $_POST["at_slider_featured"]);
    	update_post_meta($post->ID, "at_other_author", $_POST["at_other_author"]);
    }
    
    add_action( 'admin_init', 'add_at_post_box');
    
    add_action('save_post', 'save_at_post_meta');
    
    add_action('publish_post', 'save_at_post_meta');
    ?>

    Thanks so much for any help

    Matt

  2. Pioneer Valley Web Design
    Member
    Posted 2 years ago #

    A mod will remove your code soon, per forum rules use pastebin for lines greater than 10.

  3. mtedwards
    Member
    Posted 2 years ago #

    Too make sure my code is not removed... I've added it to pastebin here:

    THE CODE

    I've got the custom meta boxes displaying; a text box and a drop down list, but I can't get them to save their values to the database.

    Thanks again for any guidance you can give...

Topic Closed

This topic has been closed to new replies.

About this Topic