Title: Plugin crashes when get_fields is called in loop
Last modified: June 9, 2020

---

# Plugin crashes when get_fields is called in loop

 *  Resolved [flomei](https://wordpress.org/support/users/flomei/)
 * (@flomei)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/plugin-crashes-when-get_fields-is-called-in-loop/)
 * I’m using get_fields in a loop like this:
 *     ```
       foreach($frontpage_posts as $post) : ?>
   
          <?php
             // do foo here
             $timetoshow = '';
             if($cat[0]->slug === 'some_slug') {
                $acf = get_fields($post->ID);
                $timetoshow = $acf['my_field'];
             } else {
                $timetoshow = date('d.m.Y', strtotime($post->post_date));
             }
          ?>
   
          <!-- html output here... -->
   
       <?php endforeach; ?>
       ```
   
 * When doing that, it crashes with the following error:
 * > Fatal error: Uncaught Error: Call to a member function init() on array in /
   > my/host/wp-content/plugins/advanced-custom-fields/includes/api/api-helpers.
   > php:209
   > Stack trace:
   >  #0 /my/host/wp-content/plugins/advanced-custom-fields/includes/
   > api/api-template.php(310): acf_init() #1 /my/host/wp-content/plugins/advanced-
   > custom-fields/includes/api/api-template.php(269): get_field_objects(85, true)#
   > 2 /my/host/wp-content/themes/fwrhs/index.php(77): get_fields(85) #3 /my/host/
   > wp-includes/template-loader.php(106): include(‘/var/www/vhosts…’) #4 /my/host/
   > wp-blog-header.php(19): require_once(‘/var/www/vhosts…’) #5 /var/ww in /my/
   > host/wp-content/plugins/advanced-custom-fields/includes/api/api-helpers.php
   > on line 209
 * The post looks just fine to me, any ideas what might cause this?
    -  This topic was modified 5 years, 11 months ago by [flomei](https://wordpress.org/support/users/flomei/).
    -  This topic was modified 5 years, 11 months ago by [flomei](https://wordpress.org/support/users/flomei/).
      Reason: format code

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Elliot Condon](https://wordpress.org/support/users/elliotcondon/)
 * (@elliotcondon)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/plugin-crashes-when-get_fields-is-called-in-loop/#post-12963630)
 * Hi [@flomei](https://wordpress.org/support/users/flomei/)
 * Thanks for the question,
    Elliot here – ACF dev​​​.
 * Be aware that using the variable `$acf` in some environments can actually overwrite
   the global ACF instance. This is what your issue is.
 * Please use a different variable name such as `$fields`.
 * Cheers
    Elliot

Viewing 1 replies (of 1 total)

The topic ‘Plugin crashes when get_fields is called in loop’ is closed to new replies.

 * ![](https://ps.w.org/advanced-custom-fields/assets/icon.svg?rev=3207824)
 * [Advanced Custom Fields (ACF®)](https://wordpress.org/plugins/advanced-custom-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-custom-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-custom-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-custom-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-custom-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-custom-fields/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Elliot Condon](https://wordpress.org/support/users/elliotcondon/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/plugin-crashes-when-get_fields-is-called-in-loop/#post-12963630)
 * Status: resolved