Home Forums Add-ons Repeater Field Nested Repeater Problem: "Call to undefined function has_sub_field()"


Nested Repeater Problem: "Call to undefined function has_sub_field()"

  • I’m running:

    • WordPress v3.5.2
    • ACF v3.5.8 4.2.1
    • Gantry Framework
    • PHP Widget

    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">
    				<strong> <a href="<?php the_sub_field('qmih_floor_plan'); ?>"></a> Floor Plan:&nbsp;</strong>
    				<?php the_sub_field('qmih_description'); ?>
    				<br><em><?php the_sub_field('qmih_street_address'); ?></em>
    			<h3><?php the_sub_field('qmih_price'); ?></h3>
    		<?php endwhile; ?>
    	<?php endif; ?>
    	<?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:

    Perhaps your piece of code is running before ACF has been included?


  • 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!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Nested Repeater Problem: "Call to undefined function has_sub_field()"’ is closed to new replies.