have_rows()
doesn’t seem to find the rows of a repeater field in an options page.
I’ve tracked the issue down to the acf_get_reference()
function (api-value.php:230). That function returns null and from there on the call stack returns null/false all the way out to the template file where i called have_rows()
in the first place.
Does anyone know what’s wrong?
I’m defining the options page like this:
function hmbl_add_options_page() {
acf_add_options_page( array(
'page_title' => __('Open hours', 'hmbl'),
'capability' => 'edit_pages',
'position' => 27,
'icon_url' => 'dashicons-clock',
'post_id' => 'open-hours',
/* (string) The update button text. Added in v5.3.7. */
'update_button' => __('Update', 'hmbl'),
) );
}
add_action('acf/init', 'hmbl_add_options_page');
Then I’m getting the values in a shortcode like this:
function hmbl_openhours_shortcode() {
if( have_rows('openhours', 'option') ): ?>
<ul>
<?php while( have_rows('openhours', 'option') ): the_row(); ?>
<li><?php the_sub_field('label'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif;
}
add_shortcode('openhours', 'hmbl_openhours_shortcode');
Call stack:
acf_get_reference ([LOCAL_URL]content/plugins/advanced-custom-fields-pro/includes/api/api-value.php:233)
acf_maybe_get_field ([LOCAL_URL]content/plugins/advanced-custom-fields-pro/includes/api/api-field.php:1152)
get_field_object ([LOCAL_URL]content/plugins/advanced-custom-fields-pro/includes/api/api-template.php:121)
have_rows ([LOCAL_URL]content/plugins/advanced-custom-fields-pro/includes/api/api-template.php:469)
hmbl_openhours_shortcode ([LOCAL_URL]content/themes/[THEME_MAME]/includes/open-hours-shortcode.php:4)
do_shortcode_tag ([LOCAL_URL]wordpress/wp-includes/shortcodes.php:319)
preg_replace_callback ([LOCAL_URL]wordpress/wp-includes/shortcodes.php:197)
do_shortcode ([LOCAL_URL]wordpress/wp-includes/shortcodes.php:197)
WP_Hook->apply_filters ([LOCAL_URL]wordpress/wp-includes/class-wp-hook.php:286)
apply_filters ([LOCAL_URL]wordpress/wp-includes/plugin.php:203)
the_content ([LOCAL_URL]wordpress/wp-includes/post-template.php:240)
include ([LOCAL_URL]content/themes/[THEME_MAME]/page.php:16)
require_once ([LOCAL_URL]wordpress/wp-includes/template-loader.php:74)
require ([LOCAL_URL]wordpress/wp-blog-header.php:19)
{main} ([LOCAL_URL]index.php:18)