• So I have a custom post that has 2 custom fields. I am able to return the value for “photoname” but not “field”. Any help would be appreciated!

    Here is my functions.php

    <?php
    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'before_widget' => '<li id="%1$s" class="widget %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h2 class="widgettitle">',
    		'after_title' => '</h2>',
    	));
    }
    
    /* ///////////////////////////////////////////////////////////////////////////////// */
    /* Add Custom Photos Post */
    
    add_action('init', 'photos_register_post_type');
    
    function photos_register_post_type() {
        register_post_type('photos', array(
            'labels' => array(
                'name' => 'Photos',
                'singular_name' => 'photos',
                'add_new' => 'Add new photos',
                'edit_item' => 'Edit photos',
                'new_item' => 'New photos',
                'view_item' => 'View photos',
                'search_items' => 'Search photos',
                'not_found' => 'No photos found',
                'not_found_in_trash' => 'No photos found in Trash'
            ),
            'public' => true,
            'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
            'supports' => array(
                'title',
                'editor'
            ),
            'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
        ));
    }
    
    add_action("admin_init", "admin_init");
    
    function admin_init(){
      add_meta_box("credits_meta", "Photo:", "credits_meta", "photos", "normal", "low");
      add_meta_box("custom_meta_options", "Photo Orientation:", "custom_meta_options", "photos", "normal", "low");
    }
    
    /* ///////////////////////////////////////////////////////////////////////////////// */
    /* Add Custom Fields */
    
    /* Add Photo Custom Field */
    
    function credits_meta() {
      global $post;
      $custom = get_post_custom($post->ID);
      $photoname = $custom["photoname"][0];
      ?>
      <p><label>File Name:</label><br />
      <textarea cols="50" rows="5" name="photoname"><?php echo $photoname; ?></textarea></p>
    <?php
    }
    
    /* Add Dropdown Custom Field */
    
    function custom_meta_options(){
    	global $post;
    	$custom = get_post_custom($post->ID);
    	$field= $custom["field"][0];
    	?>
    	<strong><label>Field:</label></strong>
    	<select name="field">
    		<option value="standard">Standard</option>
    		<option value="panoramic">Panoramic</option>
    		<option value="vertical">Vertical</option>
    	</select>
    
    <?php
    }
    
    /* Save Data */
    
    add_action('save_post', 'save_details');
    
    function save_details(){
      global $post;
    
      update_post_meta($post->ID, "photoname", $_POST["photoname"]);
      update_post_meta($post->ID, "field", $_POST["field"]);
    }
    
    ?>

    And here is my page.php

    <?php get_header(); ?>
    
    		<section id="content-container">
    
    			<?php $loop = new WP_Query( array( 'post_type' => 'photos', 'posts_per_page' => 10 ) ); ?>
    
    				<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    				<div class="photo-container">
    
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img class="entry-photo" src="<?php bloginfo('template_url'); ?>/images/photos/<?php echo get_post_meta($post->ID, 'photoname', true); ?>"></a>
    
    				<span class="entry-title"><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?> | <?php the_time('F jS, Y'); ?>
    
    				</div><!-- end .photo-container -->
    				<?php endwhile; ?>
    
    		</section><!-- end #content-container -->
    
    <?php get_footer(); ?>

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I don’t see anywhere in the page.php that you tried to retrieve the ‘field’ CF. Can you show the code you tried that did not work?

    Thread Starter erikw46

    (@erikw46)

    Yes, my fault. Here is the code. The data would be entered as a class on the <img> tag.

    Thank you.

    <?php get_header(); ?>
    
    		<section id="content-container">
    
    			<?php $loop = new WP_Query( array( 'post_type' => 'photos', 'posts_per_page' => 10 ) ); ?>
    
    				<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    				<div class="photo-container">
    
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img class="entry-photo <?php echo get_post_meta($post->ID, 'field', true); ?>" src="<?php bloginfo('template_url'); ?>/images/photos/<?php echo get_post_meta($post->ID, 'photoname', true); ?>"></a>
    
    				<span class="entry-title"><?php the_title( '<a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a>' ); ?> | <?php the_time('F jS, Y'); ?>
    
    				</div><!-- end .photo-container -->
    				<?php endwhile; ?>
    
    		</section><!-- end #content-container -->
    
    <?php get_footer(); ?>

    I tested code as similar to that as I could, and it worked for me. Don’t know why it won’t work for you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Returning Multiple Meta Data Values’ is closed to new replies.