Support

Account

Forum Replies Created

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

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

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