1

I have post about this before, but I didn't get any conclusive answer but I'm really hoping someone can help me. I have setup some custom post types, and with them, some custom fields using Wordpress 3's UI.

One of the fields I have set up is called banner_image, but in the loop, it doesn't output the image.

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

This simply outputs the ID number of the post. If I set the function to false, I get an array with this ID in and nothing else. How do I get the path to the image? I can't work this out and Googling reveals a sea of content not related to my problem, it's a real difficult one to search for so you're my only hope!

Many thanks, Michael.

<?php
global $post;
$tmp_post = $post;
$args = array(

        'post_status' => 'publish',
        'post_type' => 'work',
        'order' => 'DESC'

);

$myposts = get_posts( $args );

foreach( $myposts as $post ) : setup_postdata($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) ?>">
                    <?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 endforeach; ?>
3
  • does this <?php echo get_post_meta($post->ID, 'sub_title', true); ?> works all right? Jul 1, 2011 at 10:09
  • Yes, all other basic text based custom fields created this same way seem to be working just fine. It's the "add image" field that I can't seem to get working. (banner_image) Jul 1, 2011 at 13:20
  • @Michael: What exactly is in your "add image" field? E.g. a sample value. Jul 1, 2011 at 18:08

2 Answers 2

0

Try this

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

Apparently, the custom field 'banner_image' doesn't have the right value. I guess it doesn't save the correct value first. You may want to install the Simple WP FirePHP plugin (http://wordpress.org/extend/plugins/simple-wp-firephp/) and check the value with the fb() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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