Home › Forums › Add-ons › Repeater Field › Have_rows breaks with options page, on page nesting mix
If I nest an options page repeater within a repeater which is nested inside an options page repeater, I break my site.
(Repeater or flexible content field)
Here is a simplified example:
while(have_rows("custom_modules", "option")) {
the_row();
// Some stuff
while(have_rows("sub_modules")){
the_row();
// Some more stuff
while(have_rows("social_icons", "option")){
// This while loop breaks it
the_row();
// More stuff
}
}
}
Am I missing something, is there a simple workaround, or should I elevate this to a support ticket?
remove , "options"
from the 3rd nested repeater
while(have_rows("custom_modules", "option")) {
the_row();
// Some stuff
while(have_rows("sub_modules")){
the_row();
// Some more stuff
while(have_rows("social_icons")){
// This while loop breaks it
the_row();
// More stuff
}
}
}
Thank you John.
So, this technically solved the problem I posted, but a little context is in order.
The three repeaters are in different sections of the site, so they are relatively independent of each other. The content for the third repeater will always be on the options page. The content for the first repeater may or may not be. So, a function I have does something like this:
if(have_rows('custom_modules')){
while(have_rows('custom_modules')){
function_which_accesses_modules();
}
}
elseif (have_rows('custom_modules', 'options'))
{
while(have_rows('custom_modules', 'options'){
function_which_accesses_modules();
}
}
The modules are defined in seperate files. In theory, I could write in every single module something like
if($is_inside_options_page){
while(have_rows('social_icons', 'options'){
// Get social icons
}
} else {
while(have_rows('social_icons') {
// Get social icons
}
}
Or even wrap something like that inside a function, called something like have_options_rows()
which runs have_rows() the correct way, depending on where the first have_rows() is pulling from. But I am creating the modules so that people who are only familiar with WordPress, ACF, & some of my options fields, but not my specific functions, can write modules.
I’ve just had a quick look through the ACF code and I don’t see any way to accomplish what you’re looking to do.
Technically, in one case you have a sub repeater and in the other you don’t. There isn’t any way to trick ACF into using the repeater from somewhere else as a sub repeater. The values of a sub repeater are not stored in the database in a way that would let that happen, other than perhaps writing your own custom have_rows() function, maybe have_modules()? but that would also mean writing a custom the_row() function as well I think.
Sorry, I just don’t see any way to do it, even writing custom functions, it’s not going to be easy to do.
The social_icons field is never a sub repeater. It is always a top level repeater. I just want to be able to access that top level repeater from within a sub repeater.
So, at the moment my solution is
while(have_rows("custom_modules", "option")) { // Can also be not an options page
the_row();
// Some stuff
while(have_rows("sub_modules")){
the_row();
$social_icons = get_field("social_icons", "options");
if(count($social_icons)>0) { ?>
<ul class="social-links">
<?php foreach($social_icons as $icon){ ?>
<li>
<a href="<?=$icon['social_url'];?>"><i class="fa <?=$icon['social_icon'];?>" aria-hidden="true"></i></a>
</li>
<?php } ?>
</ul>
<?php }
}
}
In my initial post, there is something about the 2nd have_rows() which makes accessing the options page in the 3rd have_rows() break the code.
You can access a top level field on the options page from within a repeater selected from the options page.
For example, this works.
while(have_rows("test", "option")) {
the_row();
if(have_rows("social_icons", "option")) {
while(have_rows("social_icons", "option")){
the_row();
the_sub_field('social_icon');
}
}
}
It selects social_icons from the top level, not as a sub field, and outputs the correct information.
The topic ‘Have_rows breaks with options page, on page nesting mix’ 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.