Title: If /else does not work with empty fields
Last modified: August 20, 2016

---

# If /else does not work with empty fields

 *  [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/)
 * Hello! I need help to solve this problem. How I can hide the data in a custom
   field that is empty? I tried many ways and I’m breaking my head.
 *     ```
       <div class="flexslider">
         <ul class="slides"><li><?php
        if ( has_post_thumbnail()) {
          $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
          echo '<a href="' . $large_image_url[0] . '" rel="lightbox[usb]" . title="' . the_title_attribute('echo=0') . '" >';
          the_post_thumbnail('medium');
   
          echo '</a>';
        }
        ?></li>
   
        <?php
          $fotos = get_order_field('fotos_fotos');
          if($fotos != ''){
          foreach($fotos as $foto){
             // el segundo parametro de la función get y get_image es el indice del grupo a mostrar
             print '<li>';
             printf('<a href="%s" rel="lightbox[usb]">', get('fotos_fotos',1,$foto) );
   
             printf('%s', get_image('fotos_fotos',1,$foto) );
       	   print '</a>';
             print '</li>';
          }
        }  else {
       print '';
       }
       ?>
        </ul>
        </div>
       ```
   
 * [http://wordpress.org/extend/plugins/magic-fields-2/](http://wordpress.org/extend/plugins/magic-fields-2/)

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/page/2/?output_format=md)

 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367697)
 * <?php
    $fotos = get_order_field(‘fotos_fotos’); ** if( !empty($fotos)){** foreach(
   $fotos as $foto){ //more code } } else { print ”; } ?>
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367701)
 * thank you! but shows the code that should be empty. you know why?
 * `<a href="" rel="lightbox[usb]"></a>`
 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367702)
 * what return
 *  <?php
    $fotos = get_order_field(‘fotos_fotos’); pr($fotos); foreach($fotos as
   $foto){ pr(get(‘fotos_fotos’,1,$foto) )); }
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367703)
 * I tried the code but still doing the same. But with a gray background and code.
 *     ```
       <div class="flexslider">
         <ul class="slides"><li><?php
        if ( has_post_thumbnail()) {
          $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
          echo '<a href="' . $large_image_url[0] . '" rel="lightbox[usb]" . title="' . the_title_attribute('echo=0') . '" >';
          the_post_thumbnail('medium');
   
          echo '</a>';
        }
        ?></li>
   
        <?php
          $fotos = get_order_field('fotos_fotos');
          pr($fotos);
          foreach($fotos as $foto){
             // el segundo parametro de la función get y get_image es el indice del grupo a mostrar
             print '<li>';
             printf('<a href="%s" rel="lightbox[usb]">', pr(get('fotos_fotos',1,$foto) ));
   
             printf('%s', get_image('fotos_fotos',1,$foto) );
       	   print '</a>';
             print '</li>';
          }
   
       ?>
   
        </ul>
   
        </div>
       ```
   
 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367704)
 * the pr function is for show the content of var
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367705)
 * ok! but there is no picture and remains
 *     ```
       <pre>Array
       (
           [0] => 1
       )
       </pre>
       ```
   
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367706)
 * I just want to show the post thumbail if no more photos in image custom fields…
 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367707)
 * And this post does not have any custom field, correctly?
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367708)
 * have a group with a repeating field image. The slide is formed by the featured
   image and the repeating field.
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367709)
 * alguien tiene una solucion?
    anyone have a solution?
 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367710)
 * the get_order_field function return having 1 field, but get return empty, right?
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367713)
 * true, and upload the images that I want, 1, 2, 3 etc. .. 0
 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367714)
 * you can write this, what return
    <?php $fotos = get_field(‘fotos_fotos’); pr(
   $fotos);
 * ?>;
 *  Thread Starter [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * (@sermalefico)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367716)
 *     ```
       Array
       (
       )
       ```
   
 *  Plugin Author [hunk](https://wordpress.org/support/users/hunk/)
 * (@hunk)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/#post-3367720)
 * it is strange that the get_order_field function returns having 1 field, but the
   get function returns no information, you could have a backup of the DB

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/page/2/?output_format=md)

The topic ‘If /else does not work with empty fields’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/magic-fields-2.svg)
 * [Magic Fields 2](https://wordpress.org/plugins/magic-fields-2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/magic-fields-2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/magic-fields-2/)
 * [Active Topics](https://wordpress.org/support/plugin/magic-fields-2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/magic-fields-2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/magic-fields-2/reviews/)

## Tags

 * [Empty Fields](https://wordpress.org/support/topic-tag/empty-fields/)
 * [if else](https://wordpress.org/support/topic-tag/if-else/)

 * 17 replies
 * 2 participants
 * Last reply from: [sermalefico](https://wordpress.org/support/users/sermalefico/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/if-else-does-not-work-with-empty-fields/page/2/#post-3367724)
 * Status: not resolved