Custom Post Type Metabox Not Displaying

Following on from this tutorial: http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/

I am trying to add some meta-boxes to allow the addition of further content to each slide. Starting with a ‘link’ metabox here is my code for slider-img-type.php:

Read More
<?php
define('CPT_NAME', "Slider Images");
define('CPT_SINGLE', "Slider Image");
define('CPT_TYPE', "slider-image");
define('CPT_THUMB_SIZE', 500);

add_theme_support('post-thumbnails', array('slider-image'));  

function efs_register() {  
    $args = array(  
        'label' => __(CPT_NAME),  
        'singular_label' => __(CPT_SINGLE),  
        'public' => true,  
        'show_ui' => true,  
        'capability_type' => 'post',  
        'hierarchical' => false,  
        'rewrite' => true,  
        'supports' => array('title', 'editor', 'thumbnail')  
       );  

    register_post_type(CPT_TYPE , $args );  
    set_post_thumbnail_size(CPT_THUMB_SIZE);
}  


add_action('init', 'efs_register');

add_action("admin_init", "efs_meta_box");   

function efs_meta_box(){
    add_meta_box("projInfo-meta", "EFS Options", "efs_meta_options", "efs", "side", "low");
}  

function efs_meta_options(){
        global $post;
        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
        $custom = get_post_custom($post->ID);
        $link = $custom["projLink"][0];
?>
    <label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />
<?php
        }

    add_action('save_post', 'save_efs_link'); 

    function save_efs_link(){  
        global $post;  

        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){ 
            return $post_id;
        }else{
            update_post_meta($post->ID, "projLink", $_POST["projLink"]); 
        } 
    }
?>

Maybe I’m missing something obvious but I can’t get the Link input field to appear when I try to add a new Slider Image post type.

Any help would be most appreciated.

Thanks,
James

Amended Code based on rmlumley’s code:

function efs_meta_options(){
        global $post;
        $custom = get_post_custom($post->ID);
        $link = $custom["projLink"][0];
?>
    <label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />  
<?php  
    }  

add_action('save_post', 'save_efs_link'); 

function save_efes_link($post_ID = 0){  
    $post_ID = (int) $post_ID;
        $post_type = get_post_type( $post_ID );
        $post_status = get_post_status( $post_ID );

        if ($post_type) {
        update_post_meta($post->ID, "projLink", $_POST["projLink"]); 
    }
return $post_ID;
}  ?>

I’ve just noticed another solution posted to the comments of the tutorial but again this doesn’t seem to be working for me:

http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/#comment-14080

I think the comments stripped out the correct code for displaying the anchor tag:

$slider.='<li><a href='.$slide_link.'>'.$img.'</a></li>';

I tried adding a custom field ‘link_slide_to’ with a url in the ‘value’ input field but the slide still displays no url on anchor hover.

Related posts

Leave a Reply

1 comment