Skip to content

Evaluate Types & Views Content; Don’t Display Empty Fields

Now that we’re all in love with Types & Views, we had to figure out how to evaluate custom fields to determine whether they should be displayed. After an hour of beating our heads against the wall, we came up with the code below. The thing that tripped us up? Check out this bit of code: msv="wpcf-wr_militaryservice". Nowhere in the documentation did it tell us that we need to prepend our field name with “wpcf-” to indicate that it’s a WordPress Custom Field. Without that, no worky. Anyway, here’s the code:

So here’s what’s going on up there. wpv-if initializes the if/then thingy. Then we created variables (mbr and msv) and the fields that the variables are drawing their value from. Then we evaluate those variables. If they’re not empty (!= ”), then go ahead and display the headers (h3) and the values of the fields. Then we close the if/then statements. Repeat until satisfied. Wet hands, wipe on pants.

stuff we dig

FYI: yes, the above are affiliate links, so we do make a small amount of money if you follow them over and buy what they're selling. Thank you for helping pay our hosting costs!

Dave Kuhar

Dave is the jack-of-all-trades running Transmit Studio, a media creation lab in San Jose. He's built more websites than he can remember, well over a hundred of them on WordPress. Whether it's tradeshow booths, video/TV, graphic design, presentations, magazine, tearsheet, and catalog layout, corporate identity packages, or just about any other kind of visual communication project, he's worked on it!

Leave a Comment





Scroll To Top