• Resolved apaimagixdk

    (@apaimagixdk)


    I use this line to display a custom field (photograoher) on single.php…

    <?php $key="photographer"; echo get_post_meta($post->ID, $key, true); ?>

    Say the custom field “photographer” has not been added to a specific post. Is there anyway to just display a standard text then – “Not known” or something like that?

    Regards,
    Anders

Viewing 4 replies - 1 through 4 (of 4 total)
  • MichaelH

    (@michaelh)

    Something like:

    <?php
    $key="photographer";
    $custom=get_post_meta($post->ID, $key, true);
    if ($custom) {
    echo $custom
    } else {
    echo 'Not known';
    }
    ?>

    Thread Starter apaimagixdk

    (@apaimagixdk)

    That returns an error… Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home...

    MichaelH

    (@michaelh)

    Oops, forgot a ;

    <?php
    $key="photographer";
    $custom=get_post_meta($post->ID, $key, true);
    if ($custom) {
    echo $custom;
    } else {
    echo 'Not known';
    }
    ?>
    Thread Starter apaimagixdk

    (@apaimagixdk)

    Thanks a million!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Field – standard text instead when no content’ is closed to new replies.