Forums

Retrieving meta value from a post (2 posts)

  1. WMS Group
    Member
    Posted 1 year ago #

    i am trying to retrieve a custom field (an image in this case) from a specific post. I can bring the custom field in, but it's not from the post I want. I have tried a few different options here, and I finally came up with this:

    <?php query_posts('meta_key=post_image_value'); ?><h3><?php the_title(); ?></h3>
    <?php while (have_posts()) : the_post(); ?>
    <img src="<?php echo get_post_meta($post->ID = 23, "post_image_value", $single); ?>"
    
    <?php endwhile; ?>

    Still not right, can anyone see what I am doing wrong here?

    Thanks.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Are you trying to get the image for the current post? If so, this should work:

    <?php query_posts('meta_key=post_image_value'); ?><h3><?php the_title(); ?></h3>
    <?php while (have_posts()) : the_post(); ?>
    <img src="<?php echo get_post_meta($post->ID, "post_image_value", $single); ?>" >
    
    <?php endwhile; ?>

    Notice that you are missing a closing greater-than to close the img tag.

Topic Closed

This topic has been closed to new replies.

About this Topic