Support » Fixing WordPress » Hiding empty custom fields

  • Resolved domino5702


    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} )
                    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


    Forum Moderator

    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.

    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.