[Plugin: Custom Field Template] Use Media Picker and output image
-
I hope someone can help me with this one as I have been going around in circles for hours!
I have created a custom field that allows the user to browse for an image in the media gallery.
I now want to output this image in the header but I can’t work out how to pass the information from get_post_meta (which pulls the attachment id) to wp_get_attachment_image (to convert that ID into an image).
I’ve tried all kinds of combinations and none of them work – I want to next one inside the other but of course I can’t do that – and I’m not as well versed in PHP as I need to be to work it out.
Here’s what I have tried most recently:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, ‘hh-product-image’, true);
?>
<?php echo wp_get_attachment_image($post->ID, ‘hh-product-image’, true); ?>I have successfully used the following to display the text in the product name field so I know the premise of calling the post information from outside the loop works:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, ‘hh-product-name’, true);
?>
<?php echo wp_get_attachment_image($post->ID, ‘hh-product-name’, true); ?>Any ideas?
- The topic ‘[Plugin: Custom Field Template] Use Media Picker and output image’ is closed to new replies.