• Resolved callender

    (@jimcallender)


    Hi there,

    I am trying to figure out how to hide the custom fields showing in the front end / browser – when i have not added an image, or text to various fields on a page?

    How, and where do i show this? ie: in wordpress template (front page) or in cmb2 file.

    thanks again.

    https://www.ads-software.com/plugins/cmb2/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Just to be certain, are you also having a user fill the fields in on the frontend? Or is content simply displayed there with the filling in happening only in the admin?

    Assuming the latter with my questions above, you should be able to check if you have a value to display, before outputting anything to the browser, and that’d allow you to only show values that exist and associated markup for them.

    Assuming the latter with my questions above, you should be able to check if you have a value to display, before outputting anything to the browser, and that’d allow you to only show values that exist and associated markup for them.

    Great do you have an example of this please?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m a big fan of the php function empty().

    $myfield = get_post_meta( get_the_ID(), 'myfield', true );
    if ( ! empty( $myfield ) ) {
        echo '<p>' . $myfield . '</p>';
    }

    Above quick snippet would only output anything if $myfield has a value saved in it.

    cheers!

    Thread Starter callender

    (@jimcallender)

    ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘don't show fields in front end when not populated with content’ is closed to new replies.