Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In wordpress 3 you can create your own custom content types (without plugins) natively.

I have done this and created a new "add image" field.

However, I'm having trouble displaying this image in my page. In the loop I am doing:

<?php echo get_post_meta($post->ID, 'banner_image', true); ?>

But, this just returns '49' (which I assume is the ID of the post). I have tried setting it to false as well, which when using var_dump() reveals an array only with this number in it. Where is the image path?

Many thanks for your help. Michael.

EDIT:

Here's a screenshot of the admin area and the image I need to output in the loop: http://i.imgur.com/hsllK.jpg

<?php

    query_posts(array( 

    'post_status' => 'publish',
    'post_type' => 'work', 
    //'orderby' => 'title', 
    'order' => 'DESC'

    ));

    while (have_posts()) : the_post(); 

    ?>

    <?php if( get_post_meta($post->ID, 'show_in_home_banner', true) == "yes" ) { ?>

    <li class="slide">

        <div class="slide-image">
            <a href="<?php echo get_page_link($post->ID) ?>">
                  <!-- this is the line outputting '49' and not the image. -->
            <?php echo get_post_meta($post->ID, 'banner_image', true); ?>
            </a>
        </div>

        <div class="slide-content">
            <h3 class="slide-header"><a href="<?php echo get_page_link($post->ID) ?>"><?php echo get_post_meta($post->ID, 'sub_title', true); ?></a></h3>
            <p class="slide-title"><strong><?php echo the_title(); ?></strong></p>
        </div>

    </li>

    <?php } ?>

    <?php endwhile; wp_reset_query(); ?>
share|improve this question

migrated from stackoverflow.com Jul 1 '11 at 17:25

This question came from our site for professional and enthusiast programmers.

    
what do you feed in to the add image field?? I mean the value. –  bingjie2680 Jun 30 '11 at 14:41
    
Well the fact that it returns something tells us that the code above is written correctly. What is the value in the custom field? Also are you using query_posts() or new WP_Query() before this at all? echo the $post->ID to make sure it's correct. –  Frank Martin Jun 30 '11 at 14:59
    
Hi guys, thanks for the help. I am going to put my loop code in the post above. I'm using query_posts() –  Michael Giovanni Pumo Jun 30 '11 at 15:26
    
Hi, here's a screenshot of the admin interface and the image I need to output in the loop. i.imgur.com/hsllK.jpg –  Michael Giovanni Pumo Jun 30 '11 at 15:41
add comment

1 Answer 1

It looks like you're using a custom plugin. Is that the case?

Anyway for the line:
<?php echo get_post_meta($post->ID, 'banner_image', true); ?>

Why aren't you using something like:

<img src="<?php bloginfo('template_url'); ?>/images/<?php echo get_post_meta($post->ID, 'banner_image', true); ?>"/>

Another way to debug is to echo the post ID to the screen and see if it is indeed 49. Let us know what's going on.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.