Forums
Forums / Fixing WordPress / Retrieving meta value from a post
(@wms-group)
15 years, 8 months 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.
(@vtxyzzy)
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.
The topic ‘Retrieving meta value from a post’ is closed to new replies.