Title: Custom Fields ( foreach giving errors when emty )
Last modified: August 22, 2016

---

# Custom Fields ( foreach giving errors when emty )

 *  [WilcoZuidema](https://wordpress.org/support/users/wilcozuidema/)
 * (@wilcozuidema)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/custom-fields-foreach-giving-errors-when-emty/)
 * Hi there,
 * I have a question, I am building a custom post type for my portfolio area on 
   my website. This is all working out very nice, but now I am running in to the
   following problem. I am using Custom Fields to Echo portfolio specification in
   a [ul] [li], to do this I copy’d and edited to following code form the wordpres
   codex site :
 *     ```
       <ul>
         <?php
             $custom_fields = get_post_custom();
             $specificaties = $custom_fields['specificaties'];
             foreach ( $specificaties as $key => $value ) {
               print " <li> " . $value . "</li>";
             }
         ?>
       </ul>
       ```
   
 * I edited it so it would not show the Value ID, but now the problem is, when a
   item doesnt go any value it gives the following error
 * `Warning: Invalid argument supplied for foreach()`
 * I am not that great with PHP just yet, I am starting to learn it bit by bit. 
   I would say that I need to add something like a ELSE ore something but everything
   I try results in errors.
 * Hope somebody can help me 🙂
 * Kind Regards,
    Wilco

The topic ‘Custom Fields ( foreach giving errors when emty )’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [WilcoZuidema](https://wordpress.org/support/users/wilcozuidema/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/custom-fields-foreach-giving-errors-when-emty/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
