Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm getting "an undefined variable in line 6" while trying to display an image from a custom field. It's pulling the name/link of file; but not image. Here is my code

<?php query_posts( 'cat=36&post_type=athletes&showposts=1&orderby=rand'); ?>
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="">
  <a href="<?php the_permalink() ?>">Read More</a>

 <?php $imageid = get_post_meta($post->ID, 'athletethumbnail', true); ?>
 <img src="<?php echo wp_get_attachment_url( $imageid ); ?>" height="192" width="192" />
          <?php the_title(); ?>


  <?php endwhile; ?>
  <?php else : ?>
  <?php endif; ?>
share|improve this question

1 Answer 1

Try this:

<?php $imageid = get_post_meta(get_the_ID(), 'athletethumbnail', true); ?>

Also, you might want to read this.

share|improve this answer

Your Answer


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

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