Support

Account

Home Forums Add-ons Flexible Content Field Get another page's Flexible Content

Solved

Get another page's Flexible Content

  • Hello,

    I’m having some issues trying to access another pages Flexible Content. I’ve created a Page Builder using the Flexible Content functionality and I’m trying to access the field data in another page’s (preferably by ID) Page Builder sub fields, sub fields.

    So for example.

    I have a class called builder.php which is the flexible field loop / logic.

    if( have_rows('page_builder') ):
        while ( have_rows('page_builder') ) : the_row();
    
            if ( get_row_layout() == 'full_width_banner' ):
                echo '<div class="fwb fwb-default">' . get_sub_field('fwb_text') . '</div>';
    
            elseif ( get_row_layout() == 'four_column_grid' ):
                /* etc etc */
    
            endif;
    
        endwhile;
    endif;

    So what effectively I’m trying to do is, if another page (we’ll call it page 2) say for example has its own instance of 'full_width_banner' on it’s instance of the builder.

    I want to be able to get the sub_field of page 2 from the builder instance on page 1. For example:

    if ( have_rows(get_field('page_builder', $this_pages_id)) ) { 
        // loop rows in that instance 
    }

    Thanks,

    Connor

  • if(have_rows('page_builder', $this_page)):
          while(have_rows('page_builder', $this_page)): the_row();
              if( get_row_layout() == 'page_content_block' ):
    
    	          $this_text = get_sub_field('page_content_editor');
    	          $this_text_plain = strip_tags($this_text);
    
                    // flexible row logic
              endif;
          endwhile;
    endif;

    I found that if you try and pass get_sub_field('repeater_page_object')->ID as the have_rows() $id parameter, it will cause an infinite loop, however, if you store these values as a variable on each loop index it works fine.

    The above is an example of how I managed to get the result I wanted. This was placed within a flexible content loop in a if (get_row_layout == 'x') { } statement.

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

You must be logged in to reply to this topic.