Title: Hiding empty custom fields
Last modified: August 19, 2016

---

# Hiding empty custom fields

 *  Resolved [domino5702](https://wordpress.org/support/users/domino5702/)
 * (@domino5702)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hiding-empty-custom-fields/)
 * I have defined a custom post type, and with it, a number of custom fields that
   are displayed. All is well, except, I cannot hide fields, when they are not filled
   in. This is how I tried to do it:
 *     ```
       function the_brb_meta() {
           global $id;
   
           if ( $keys = get_post_custom_keys() ) {
               foreach ( $keys as $key ) {
                   $keyt = trim($key);
                   if ( '_' == $keyt{0} )
                       continue;
                       echo "<ul class=\"post-meta\">\n";
                          $values = array_map('trim', get_post_custom_values($key));
                       $value = implode($values,', ');
                       if(!empty($key)) {
                              echo "<li><span class=\"post-meta-key\">$key:</span> $value</li>\n";
                           echo "</ul>\n";
                           }
                   }
           }
       }
       ```
   
 * but the empty fields still show up. What is wrong with my code’s logic?
 * Any help appreciated.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hiding-empty-custom-fields/#post-1676090)
 * it seems that the opening `<ul ...>` is outside your conditional check;
 * also, i would assume that you would need to check the $value, and not the $key.
 *  Thread Starter [domino5702](https://wordpress.org/support/users/domino5702/)
 * (@domino5702)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/hiding-empty-custom-fields/#post-1676111)
 * Oh, golly, seems like I should have increased my intake of coffee bewfore posting.
   Thanks, mate!

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

The topic ‘Hiding empty custom fields’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [domino5702](https://wordpress.org/support/users/domino5702/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/hiding-empty-custom-fields/#post-1676111)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
