Title: Custom Fields
Last modified: August 19, 2016

---

# Custom Fields

 *  Resolved [awx2d](https://wordpress.org/support/users/awx2d/)
 * (@awx2d)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-6/)
 * Hi I am using the code developed by theundersigned to build the xml doc, the 
   script is below, I want to pull out a custom field from each post to be used 
   as an album image i.e. in each <gallery></gallery> there will be an <album id
   =”foo” description=”bar” src=”<The custom field value>”, any help or advise on
   this would be greatly appreciated!
 *     ```
       <?php
       require('./wp-config.php');
       header('Content-type: text/xml; charset=utf-8'); 
   
       function ssp_fetch_images($postid, $size) {
           global $wpdb;
           return $wpdb->get_results("SELECT guid, post_title, post_content FROM $wpdb->posts WHERE post_parent = $postid AND post_mime_type = 'image/jpeg'");
       } 
   
       if(isset($_GET['cat'])) {
       $cat = $_GET['cat'];
       $query = "cat=$cat&showposts=1000";
       } else {
       $query = "showposts=1000";
       } ?>
       <gallery>
           <?php $gallery = new WP_Query($query);
           while ($gallery->have_posts()) : $gallery->the_post(); ?>
           <album title="<?php echo htmlspecialchars($post->post_title); ?>" description="<?php echo htmlspecialchars($post->post_content); ?>">
               <?php $images = ssp_fetch_images($post->ID);
               foreach($images as $image) { ?>
               <img src="<?php echo $image->guid; ?>" tn="<?php echo str_replace(".jpg", ".thumbnail.jpg", $image->guid); ?>" title="<?php echo htmlspecialchars($image->post_title); ?>" caption="<?php echo htmlspecialchars($image->post_content); ?>" />
               <?php } ?>
           </album>
           <?php endwhile; ?>
       </gallery>
       ```
   

The topic ‘Custom Fields’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [awx2d](https://wordpress.org/support/users/awx2d/)
 * Last activity: [17 years, 11 months ago](https://wordpress.org/support/topic/custom-fields-6/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
