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 runs Transmit Studio, a media creation lab in San José. He's built more websites with WordPress than he can remember. He likes hearing himself talk and writing about himself in third person.

Leave a Comment