0

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

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

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">
              <h3>Ingredients</h3>
              <?php echo wpautop( get_post_meta( get_the_ID(), $post . '_cmb_fe_wysiwyg', true ) );?>
        </div>
  <?php } ?>

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

  • 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.