• Resolved Nathan Hawkes

    (@natehawkes)


    I have just downloaded Simple Fields and I think it’s fantastic. Just one query:

    I am creating a custom events page and have an option to add event sponsors (fields provided by SF). Is it possible to have the sponsors section disappear if there are no meta options? Here is my code now:

    <?php
                  $event_sponsors = simple_fields_values( 'wca_events_sponsors_logo, wca_events_sponsors_name' );
                  if ( empty( $event_sponsors ) ) { ?>
                <ul id="event-sponsors-list" class="event-list">
                  <?php foreach( $event_sponsors as $event_sponsor ) { ?>
                  <li style="background-image: url('<?php echo $event_sponsor['wca_events_sponsors_logo']['url']; ?>');" title="<?php echo $event_sponsor['wca_events_sponsors_name']; ?>">
                  </li>
                  <?php } ?>
                </ul>
                <?php } ?>

    A var_dump of $event_sponsors gives:

    array(0) { }

    so in theory, empty() should work. Right? Is there something I’ve missed?

    https://wordpress.org/plugins/simple-fields/

Viewing 1 replies (of 1 total)
  • Thread Starter Nathan Hawkes

    (@natehawkes)

    Sorry, that would be my mistake. It’s late here in the UK -_-“

    I should have had !empty( $event_sponsors ), not empty( $event_sponsors ).

Viewing 1 replies (of 1 total)
  • The topic ‘Do something when nothing is in the array’ is closed to new replies.