WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hiding empty custom fields (3 posts)

  1. domino5702
    Member
    Posted 3 years ago #

    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.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    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.

  3. domino5702
    Member
    Posted 3 years ago #

    Oh, golly, seems like I should have increased my intake of coffee bewfore posting. Thanks, mate!

Topic Closed

This topic has been closed to new replies.

About this Topic