Title: Display Custom Field Data In Loop
Last modified: August 19, 2016

---

# Display Custom Field Data In Loop

 *  [product247](https://wordpress.org/support/users/product247/)
 * (@product247)
 * [15 years ago](https://wordpress.org/support/topic/display-custom-field-data-in-loop/)
 * I need to display custom field data from all subpages of a parent page in the
   loop. Here is the code to display all of the featured thumbnail images of subpages
   in the loop. But I need to convert this code to display a custom field variable
   instead. Can anyone help me with this? Here is the featured thumbnail code below:
 *     ```
       <?php query_posts(array('post_parent' => 19, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
                   <?php if ( has_post_thumbnail() ) {?>
                       <?php the_post_thumbnail(); ?>
                   <?php } else { ?>
                       <!-- Else Don't show anything -->
                   <?php } ?>
           <?php } ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/display-custom-field-data-in-loop/#post-2045436)
 * [http://codex.wordpress.org/Custom_Fields](http://codex.wordpress.org/Custom_Fields)
   
   [http://codex.wordpress.org/Function_Reference/get_post_meta](http://codex.wordpress.org/Function_Reference/get_post_meta)
 *  [Daniel Gilfoy](https://wordpress.org/support/users/dgilfoy/)
 * (@dgilfoy)
 * [15 years ago](https://wordpress.org/support/topic/display-custom-field-data-in-loop/#post-2045437)
 * The short answer:
    <?php echo get_post_meta($post->ID,’custom-field-name’,true)?
   >
 * 🙂
 *  Thread Starter [product247](https://wordpress.org/support/users/product247/)
 * (@product247)
 * [15 years ago](https://wordpress.org/support/topic/display-custom-field-data-in-loop/#post-2045455)
 * Here is what I did so far:
 *     ```
       <?php query_posts(array('post_parent' => 19, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
           <a href='<?php the_permalink() ?>' rel="bookmark">
              <li class="menuItem"><img src="<?php echo get_post_meta($post->ID, 'navigation_thumbnail', true) ?>" alt="<?php the_title(); ?>" />
           </a></li>
           <?php } ?>
       ```
   
 * It is pulling the sub categories and displaying the alt text but when I view 
   the source the image location is empty. Could you tell me what I am doing wrong?
   Thank You
 *  Thread Starter [product247](https://wordpress.org/support/users/product247/)
 * (@product247)
 * [15 years ago](https://wordpress.org/support/topic/display-custom-field-data-in-loop/#post-2045485)
 * Actually I realized that the above code works.. Thanks Guys!!!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Display Custom Field Data In Loop’ is closed to new replies.

## Tags

 * [custom field data](https://wordpress.org/support/topic-tag/custom-field-data/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [product247](https://wordpress.org/support/users/product247/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/display-custom-field-data-in-loop/#post-2045485)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
