• Hi,

    I am creating my first plugion to take advantage of custom post types and I think it’s almost there, i just can’t get it to display the meta information “kvl_gallery_image_a” or “kvl_gallery_image_b”

    What am I doing wrong, can anyone help?

    heres the function file:

    function kvlgallery_post_types_register() {
    	register_post_type( 'kvlgallery',
    		array(
    			'labels' => array(
    				'name' => __( 'Gallerys' ),
    				'singular_name' => __( 'Gallery' ),
    				'add_new' => __( 'Add New Gallery' ),
    				'add_new_item' => __( 'Add New Gallery' ),
    				'edit' => __( 'Edit' ),
    				'edit_item' => __( 'Edit Gallery' ),
    				'new_item' => __( 'New Gallery' ),
    				'view' => __( 'View Gallery' ),
    				'view_item' => __( 'View Gallery' ),
    				'search_items' => __( 'Search Gallerys' ),
    				'not_found' => __( 'No Gallerys' ),
    				'not_found_in_trash' => __( 'No Gallerys in the Trash' ),
    			),
    			'public' => true,
    			'hierarchical' => false,
    			'exclude_from_search' => false,
    			'menu_position' => 30,
    			'menu_icon' => plugins_url( 'icons/user_comment.png' , __FILE__ ),
    			'query_var' => true,
    			'can_export' => true,
    			'has_archive' => 'Gallerys',
    			'description' => "A galley page contains a selection of photos taken by Keith Van Loen grouped by theme or shoot.",
    			'rewrite' => array('slug' => 'Gallery'),
    			'supports' => array( 'title', 'excerpt', 'editor', 'thumbnail' ),
    
    		)
    	);
    }
    
    add_action( 'init', 'kvlgallery_post_types_register' );
    
    function kvlgallery_fields () {
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$kvlgallery_image_a = $custom["kvlgallery_image_a"][0];
    	$kvlgallery_image_b = $custom["kvlgallery_image_b"][0];
    	?>
    
        <p>
        <label>Image 1</label><br />
        <input size="45" name="kvlgallery_image_a" value="<?php echo $kvlgallery_image_a; ?>" />
        </p>
    	<p>
        <label>Image 2</label><br />
        <input size="45" name="kvlgallery_image_b" value="<?php echo $kvlgallery_image_b; ?>" />
        </p>
    
    	<?php
    }
    
    function add_kvlgallery_box(){
    	add_meta_box(
    		"kvlgallery_info",
    		"Gallery Images",
    		"kvlgallery_fields",
    		"kvlgallery"
    		);
    }
    
    function save_kvlgallery_attributes(){
    	global $post;
        update_post_meta($post->ID, "kvlgallery_image_a", $_POST["kvlgallery_image_a"]);
    	update_post_meta($post->ID, "kvlgallery_image_b", $_POST["kvlgallery_image_b"]);
    }
    
    add_action( 'admin_init', 'add_kvlgallery_box' );
    add_action( 'save_post', 'save_kvlgallery_attributes' );
    add_action( 'publish_post', 'save_kvlgallery_attributes' );
    
    function create_kvlgallery_taxonomy() {
    
        $genrelabels = array(
          'name' => 'genre',
          'singular_name' => 'genre',
          'search_items' =>  'Search genres',
          'popular_items' => 'Popular genres',
          'all_items' => 'All genres',
          'parent_item' => null,
          'parent_item_colon' => null,
          'edit_item' => 'Edit genre',
          'update_item' => 'Update genre',
          'add_new_item' => 'Add new genre',
          'new_item_name' => 'New genre name',
          'separate_items_with_commas' => 'Separate genres with commas',
          'add_or_remove_items' => 'Add or remove genres',
          'choose_from_most_used' => 'Choose from common genres',
          'menu_name' => 'Gallery Genres',
        );
        register_taxonomy( 'kvlgallery_genre', 'kvlgallery',
            array(
           'hierarchical' => false,
                 'labels' => $genrelabels,
                 'query_var' => true,
                 'update_count_callback' => '_update_post_term_count',
                 'rewrite' => array('slug' => 'genres' )
            )
        );
    }
    
    add_action('init', 'create_kvlgallery_taxonomy', 0);
    ?>

    and here’s the prototype single.php page

    <?php while ( have_posts() ) : the_post(); ?>
    
    					<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
                        <h1>KVL Gallery Page Template</h1>
    
    					<?php the_title(); ?>
    
                        <?php the_content(); ?>
    
    					<p><?php echo get_post_meta($post->ID, 'kvl_gallery_image_a', true) ?></p>
    
                        <p><?php echo get_post_meta($post->ID, 'kvl_gallery_image_b', true); ?></p>
    
                        </article>
    				<?php endwhile; // end of the loop. ?>

    Hope someone can help show me where I am going wrong!

    Thanks

  • The topic ‘I can't get custom post types to display meta post information’ is closed to new replies.