Title: Custom Fields
Last modified: August 19, 2016

---

# Custom Fields

 *  Resolved [Emily1](https://wordpress.org/support/users/emily1/)
 * (@emily1)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-18/)
 * I finally have the right code, I think, to get my address custom field to show
   on each post. The problem is that not all of my posts have addresses. The posts
   without an address have an error that says Warning: Invalid argument supplied
   for foreach() in /data/16/1/37/96/1852748/user/2011364/htdocs/wp-content/plugins/
   thesis-openhook/functions.php(453) : eval()’d code on line 5.
 * Here is the code I’m using:
 *     ```
       <?php
         global $post;
         $custom_fields = get_post_custom(0);
         $address = $custom_fields['address'];
         foreach ( $address as $key => $value )
           echo $key . " : " . $value . "<br />";
       ?>
       ```
   
 * How should I modify it so that it doesn’t try to show the address field for posts
   without an address field?
 * Also, the output comes out something like this:
 * 0 : 3208 Wellington Ct., Ste. 109, Raleigh, NC 27615
 * How do I change the 0 to say Address?

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

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-18/#post-1250264)
 *     ```
       if ( $address ) {
         foreach ( $address as $key => $value )
           echo $key . " : " . $value . "<br />";
       }
       ```
   
 * Try this on the 0 issue
 *     ```
       if ( $address ) {
         foreach ( $address as $key => $value )
           echo "Address: " . $value . "<br />";
       }
       ```
   
 *  Thread Starter [Emily1](https://wordpress.org/support/users/emily1/)
 * (@emily1)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-18/#post-1250318)
 * Thanks very much!

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

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Emily1](https://wordpress.org/support/users/emily1/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-18/#post-1250318)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
