• Resolved nessler

    (@nessler)


    Hi,

    working with the newspaper theme and building a (mainly) music entertainment website, we would need to place a custom field into a block module.

    we have achieved this with the following code,

    <span class='metacelocation'><?php echo get_post_meta($this->post->ID, 'concertlocatie',TRUE); ?></span>

    however, in css we add a “x” prior to this field, since this is the way we want things to be seperated, like so:

    .metacelocation::before { 
        content: " x ";
    }

    however when the custom field is empty, it still shows the x, something we were hoping to make disappear.
    In other parts of the site that don’t use the $this argument we have achieved this with an empty get field false argument like below, however this time it doesn’t work and we can’t figure it out ourselves.

    anyone who can shine a light on this ?

    <span class='metacelocation'><?php if (empty(get_field('concertlocatie')) === false): ?><?php echo the_field('concertlocatie'); ?></span>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    You can change this code
    <span class='metacelocation'><?php echo get_post_meta($this->post->ID, 'concertlocatie',TRUE); ?></span>

    to

    <span class='metacelocation'><?php $conc = get_post_meta($this->post->ID, 'concertlocatie',TRUE); if(!empty($conc)): echo $conc; endif; ?></span>

    If you want to place ‘x’ here then you can by replacing echo $conc; to echo " x ".$conc;

    Thanks

    Thread Starter nessler

    (@nessler)

    that worked even better than a magic trick, thanks a lot !

    Great ?? Please mark it resolved.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘To not show a custom field if empty’ is closed to new replies.