I am having trouble hiding a div when the input of a custom field is empty. This is the code I am using but can not seem to get it to work. The field that displays the content is _cmb_fe_wysiwyg

        if( empty( $post->post_content) ) {
        else {
              echo '<div id="ingredientsNeeded">';
                    echo '<h3>Ingredients</h3>';
                  echo wpautop( get_post_meta( get_the_ID(), $prefix . '_cmb_fe_wysiwyg', true ) ); 
                  echo '</div>';

I think what you are looking for is something like:

 <?php $post = get_post_meta($post->ID, '_cmb_fe_wysiwyg', true) ; if (!empty($post)) { ?>
        <div id="ingredientsNeeded">
              <?php echo wpautop( get_post_meta( get_the_ID(), $post . '_cmb_fe_wysiwyg', true ) );?>
  <?php } ?>

This will check that the value is empty and if so will hide the div

| improve this answer | |
  • perfect that worked like a charm – user3756781 Jul 15 '14 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.