Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I cannot see what is incorrect here, I'm trying to hide an entire element if all (and some) options are empty, but it is hiding everything even though at least options are filled in.

My code:

    <?php $sitename = get_bloginfo( 'description' );
          $phone1 = get_option( 'show_phone1' );
          $phone2 = get_option( 'show_phone2' );
          $email = get_option( 'show_email' );
          $address1 = get_option( 'show_address1' );
          $address2 = get_option( 'show_address2' );
          $town = get_option( 'show_town' );
          $county = get_option( 'show_county' );
          $postcode = get_option( 'show_postcode' );
    if ( ! empty( $sitename ) && ( ! empty( $phone1 ) || ! empty( $phone2 ) ) && ! empty( $email ) && ( ! empty( $address1 ) && ! empty( $address2 ) ) && ! empty( $town ) && ! empty( $county ) && ! empty( $postcode ) ) : ?>
        <div class="site-contact">

        <?php if ( ! empty( $sitename ) ) : ?>
            <span><?php echo get_bloginfo( 'name' ); ?></span>

        <?php endif; if ( ! empty( $phone1 ) ) : ?>
            <span><?php echo get_option( 'show_phone1' ); ?></span>

        <?php endif; if ( ! empty( $phone2 ) ) : ?>
            <span><?php echo get_option( 'show_phone2' ); ?></span>

        <?php endif; if ( ! empty( $email ) ) : ?>
            <span><a href="mailto:<?php echo get_option( 'show_email' ); ?>" title="Send and email to <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><?php echo get_option( 'show_email' ); ?></a></span>

        <?php endif; if ( ! empty( $address1 ) ) : ?>
            <span><?php echo get_option( 'show_address1' ); ?></span>

        <?php endif; if ( ! empty( $address2 ) ) : ?>
            <span><?php echo get_option( 'show_address2' ); ?></span>

        <?php endif; if ( ! empty( $town ) ) : ?>
            <span><?php echo get_option( 'show_town' ); ?></span>

        <?php endif; if ( ! empty( $county ) ) : ?>
            <span><?php echo get_option( 'show_county' ); ?></span>

        <?php endif; if ( ! empty( $postcode ) ) : ?>
            <span><?php echo get_option( 'show_postcode' ); ?></span>

        <?php endif; ?>

        </div><!-- .site-contact -->
    <?php endif; ?>

Any help is much appreciated, please bare in mind I (obviously) do not code PHP.. I'm just trying my hand at some editing.. which is always fun.

share|improve this question
    
This isn't actually a WP question, but I'll answer anyway. –  vancoder Jul 4 '13 at 17:31
add comment

closed as off-topic by s_ha_dum, Michael, Johannes Pille, brasofilo, toscho Jul 4 '13 at 21:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to WordPress are off-topic here, but can be asked on Stack Overflow." – s_ha_dum, Michael, Johannes Pille, brasofilo, toscho
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

I'm guessing that address2 is not required, is that right? If so, then you have an 'and' operator where you should have an 'or' operator:

( ! empty( $address1 ) && ! empty( $address2 ) )

should be

( ! empty( $address1 ) || ! empty( $address2 ) )
share|improve this answer
add comment

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