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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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="http://schema.org/BlogPosting">
  <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(); ?>

  </article>

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

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

 
discard

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.