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.