Ready to get started?Download WordPress


Custom meta box, how to get value? (1 post)

  1. mYrAn
    Posted 2 years ago #


    I just started messing around with custom post types, and i've added a custom meta box. The problem i have is that i cant get the values from them in my template. My code looks like this

    add_action("admin_init", "admin_init");
    add_action('save_post', 'save_movie');
    function admin_init(){
    	add_meta_box("film-info-meta", "Film Information", "meta_options", "film", "side", "low");
    function meta_options(){
    	global $post;
    	$film = get_post_custom($post->ID);
    	$duration = $film["duration"][0];
    	$imdb = $film["imdb"][0];
    		<p>Längd (min):<br /><input name="duration" value="<?php echo $duration; ?>" /></p>
            <p>IMDB Betyg:<br /><input name="imdb" value="<?php echo $imdb; ?>" /></p>
    function save_movie(){
    	global $post;
    	update_post_meta($post->ID, "duration", $_POST["duration"]);
    	update_post_meta($post->ID, "imdb", $_POST["imdb"]);

    I dont know much php, that's why i dont know how to get it. I tried <?php echo get_post_meta($post->ID, "duration"); ?> but that just says Array..

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.