check if any custom field with certain name has value
-
I’m trying to show content, when either one of four custom fields is used.
I’m trying to show a link to the online shop for a certain record if it’s entered. I have 4 custom fields available for this.
I have this
<p class="buy">Buy online: <?php $key = "beatport"; $bietport = get_post_meta($post->ID, $key, true); if ($bietport) { ?><a href="<?php $key="beatport"; echo get_post_meta($post->ID, $key, true); ?>">Beatport</a><?php } ?> <?php $key = "junodownload"; $juno = get_post_meta($post->ID, $key, true); if ($juno) { ?><a href="<?php $key="junodownload"; echo get_post_meta($post->ID, $key, true); ?>">Juno</a><?php } ?> <?php $key = "rushhour"; $rh = get_post_meta($post->ID, $key, true); if ($rh) { ?><a href="<?php $key="rushhour"; echo get_post_meta($post->ID, $key, true); ?>">Rush Hour</a><?php } ?> <?php $key = "discogs"; $dg = get_post_meta($post->ID, $key, true); if ($dg) { ?><a href="<?php $key="discogs"; echo get_post_meta($post->ID, $key, true); ?>">Discogs</a><?php } ?> </p>
I’ve tried this code but doesn’t work. It always gives Yes, even if no values are entered. It works with 1 value, but when more values come into play, it doesn’t anymore…
<?php $bietport = get_post_meta($post->ID, $beatport, true); $juno = get_post_meta($post->ID, $junodownload, true); $rh = get_post_meta($post->ID, $rushhour, true); $dg = get_post_meta($post->ID, $discogs, true); if ($bietport || $juno || $rh || $dg) { ?> YES <?php } else { ?> NO <?php } ?>
The first part should come where it says YES and no will be removed (if I get it working)
Hoping somebody knows an answer…
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘check if any custom field with certain name has value’ is closed to new replies.