Using Multiple Custom Fields in IF Statements
-
I was wondering if anyone knew a clean way to use multiple custom fields in an IF statement.
At the moment I have it spaced out, so each custom field “SponsorHeading#” has it’s own if/else statement:
if(get_post_meta($post_id, 'SponsorHeading1', true)) { echo '<h2>Summit Sponsors </h2>'; } else { echo ''; } if(get_post_meta($post_id, 'SponsorHeading2', true)) { echo '<h2>Summit Sponsors </h2>'; } else { echo ''; } and so on for 3 more custom fields. I'd like to have something cleaner like: if(get_post_meta($post_id, 'SponsorHeading2', true)) || if(get_post_meta($post_id, 'SponsorHeading2', true)) || if(get_post_meta($post_id, 'SponsorHeading2', true)) { echo '<h2>Summit Sponsors </h2>'; } else { echo ''; }
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
or something along those lines to clean it up but nothing I’ve tried has worked.
Any suggestions?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Using Multiple Custom Fields in IF Statements’ is closed to new replies.