Home › Forums › Add-ons › Repeater Field › Nested Repeater Problem: "Call to undefined function has_sub_field()"
I’m running:
I’m using the Gantry Framework (widgetized layouts) and the PHP Widget plugin to allow the rapid creation and editing of a custom backend for my client. Everything has been going quite well until I tried to do a nested repeater. Using the code provided in your “Working with nested repeaters” article (my php knowledge is not extensive), I came up with this:
<?php if( get_field('qmih_location_area') ): ?>
<?php while( has_sub_field('qmih_location_area') ): ?>
<h2><?php the_sub_field('qmih_area_name'); ?></h2>
<div class="qmih_listing">
<?php if( get_field('qmih_entry') ): ?>
<?php while( has_sub_field('qmih_entry') ): ?>
<div class="qmih_entry">
<img src="<?php the_sub_field('qmih_image'); ?>" width="200">
<p>
<strong> <a href="<?php the_sub_field('qmih_floor_plan'); ?>"></a> Floor Plan: </strong>
<?php the_sub_field('qmih_description'); ?>
<br><em><?php the_sub_field('qmih_street_address'); ?></em>
</p>
<h3><?php the_sub_field('qmih_price'); ?></h3>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
But it always breaks the page it’s on, and returns the error:
Fatal error: Call to undefined function has_sub_field() in /home/wp-content/67/8176767/html/wp-content/plugins/wp-php-widget/wp-php-widget.php(52) : eval()'d code on line 2
I realize I’m running an older version of the ACF plugin, but I’m hesitant to update it because I don’t want it to break my site. I’ve updated the plugin (and activated the repeater field), but the problem persists. Any pointers? Any issues with the code above?
UPDATE: I’ve installed the latest version of ACF (4.2.1) and activated the repeater add-on, and the problem still persists. Please help!
Hi @logangreer
The has_sub_field function is defined in /core/api.php on line 413:
https://github.com/elliotcondon/acf/blob/master/core/api.php#L413
Perhaps your piece of code is running before ACF has been included?
Thanks
E
That could possibly be the case, since it’s PHP in a widget (when is that loaded?). Though the other simple “the_field” PHP code seems to work fine elsewhere.
Is there any way to force the “has_sub_field” function to be loaded first? Like with a PHP snippet before the repeater bit?
I’ve been pulling my hair out on this, but I think I’ve tracked down the problem. I had moved my WordPress installation to a subfolder on the server and left out a simple line of code, and the ACF was still looking in the old location for the api.php file. For some reason, some things were working and others weren’t. But I think I’ve fixed it.
I Believe that solves this issue as an error on my end. Sorry to use up your time!
The topic ‘Nested Repeater Problem: "Call to undefined function has_sub_field()"’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.