• Resolved jarvo1980

    (@jarvo1980)


    Hi All,

    I’ve a custom field which displays a date. What I’d like to do is not show the title of the custom field or it’s content if it’s blank, however, my code below still shows the title Date when there is no content. What’s wrong with the below?

    <?php if( get_post_meta($key, 'date') !== '' ) { ?>
    <?php $key="date"; echo  $key.' '; ?>
    <?php $key="date"; echo get_post_meta($post->ID, $key, true); ?>
    <?php } ?>

    Should the above not be fine to use?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anonymous User

    (@anonymized-3085)

    I’d probably use something like this:

    $data=get_post_meta($post->ID, $key, true);
    if($data!='')
    echo 'title '.$data;

    Thread Starter jarvo1980

    (@jarvo1980)

    Thanks Rich ‘elfin’ Pedley, worked a treat!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom field display nothing if blank’ is closed to new replies.