Support » Fixing WordPress » display text only when custom field is filled

  • Resolved AndresHolmes

    (@andresholmes)


    Hi,
    I’m using plugin More Fields and have this code in single.php
    zdroj: <a href="<?php echo get_post_meta($post->ID, 'zdroj', true);?>"> <?php echo get_post_meta($post->ID, 'szdroj', true);?> </a>
    I want to display the output only when there is something written in the “zdroj”. How can I do it?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this (UNTESTED):

    <?php
    $zdroj = get_post_meta($post->ID, 'zdroj', true);
    if ($zdroj) :
    ?>
    zdroj: <a href="<?php echo $zdroj;?>"> <?php echo get_post_meta($post->ID, 'szdroj', true);?> </a>
    <?php endif; ?>

    it’s working, thanks very much

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘display text only when custom field is filled’ is closed to new replies.