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.

I would like to display data from a post that has custom fields in a metabox. One of the fields is the URL for an image. How do I create an echo to display the image?

The other field I want to call is a link. I have one field for the URL and one field for the link text. How do I echo this to diplay the link.

Thanks,

14ner

share|improve this question
    
Did either of our answers give you what you needed? If so, go ahead and click the "check mark" icon by one of our answers. Thanks 14ner! –  Jonathan Wold May 26 '11 at 15:40

2 Answers 2

Within your Query loop, using your image URL as an example, put this:

<?php $image_url = get_post_meta($post->ID, 'image-url-field', true); ?>

Replace "image-url-field" with the name of your custom field.

Then, also within that same loop, do this:

<?php echo $image_url; ?>

Reference: http://codex.wordpress.org/Function_Reference/get_post_meta

share|improve this answer

I think what we want might be something more like:

<?php
  $image_url = get_post_meta($post->ID, 'image-url-field', true);
  $link_url = get_post_meta($post->ID, 'link-url-field', true);
  $link_text = get_post_meta($post->ID, 'link-text-field', true);

  // display inline image
  echo '<img src="' . esc_url($image_url) . '" />';

  // display clickable link
  echo '<a href="' . esc_url($link_url) . '">' . esc_html($link_text) . '</a>';
?>
share|improve this answer

Your Answer

 
discard

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