I’ve got a number of custom fields in a WP theme, and I want to check if they have values – but would like a short cut to check multiple values at once – something like this:
if ( get_post_meta ( $post->ID, "first_value", "second_value", "third_value", $single = true) !="") :
// do stuff here, as they are all set ##
else:
// do something else, as they are not all set ##
endif;
this does not throw an error, but it only checks if the first value is set – any ideas?
First note the affects of setting the $single variable to true:
Solution 1: That being said you could then use $single=false to get an array of values, and then compare the array of values to an array of null values.
Solution 2: Or you could use several conditions in the if_else statement:
Solution 3: You could also use nested if_then statements if you prefer those.
The question is, which solution works best for you?