Home Forums Add-ons Flexible Content Field get_row_layout returns empty string when called from subsite


get_row_layout returns empty string when called from subsite

  • I’m running a multisite and on the main site, I have a post which includes custom fields as well as a flexible content field.

    Then on a subsite, I am switching to the main blog and showing content from the post on the main site.

    All content is loading fine, except for flexible content. The code is getting the number of rows, however get_row_layout returns blank. Weird thing is that i have the same codebase as my colleague – and for him it’s working. So I believe this may be an issue with how the custom fields are in the database?

    Here’s the code, it’s including some debug code I got from another thread:

    // check if the flexible content field has rows of data
    if( have_rows('content') ):
      echo '<pre>';
      print_r( 'value exists' );
      echo '</pre>';
      $i = 0;
       // loop through the rows of data
      while ( have_rows('content') ) : the_row();
          echo '<pre>';
            print_r( 'Within loop: ' . $i . ', layout: ' . get_row_layout() );
          echo '</pre>';
          $content = get_row_layout();
          echo $content;
          if($content == 'olapic_gallery') {
          get_template_part('content/block', $content);
    else :
      // no layouts found

    What this is outputting:


    value exists
    Within loop: 1, layout:
    Within loop: 2, layout:
    Within loop: 3, layout:


    This is driving me mad – especially since on my colleague’s dev site everything works as expected – it pulls in the data from the flexible content field. Any ideas?

    UPDATE #1
    Doing a bit more digging on the above problem. I am outputting all postmeta to the page and it appears that the values are there for the flexible content fields.

    Post Meta output

    So still confused as to what is happening, I decided to have a look inside the ACF source code inside the get_row_layout function. It looks like it isn’t getting inside this if statement, located on line 655 of api.php:

    // return value
    if( isset($row['value'][ $row['i'] ][ $field_name ]) )
      echo "we have found a value";
      return $row['value'][ $row['i'] ][ $field_name ];

    Just to reiterate: showing flexible content works fine when on the same site as the post. When I am on a subsite and switching blogs, the flexible content does not return. All other custom fields do though.

    UPDATE #2:

    Sorry just one more update, I’m echoing out the $value that is returned in the get_row_layout function. When I’m on a subsite, this is a returning a string. But on the mainsite, it returns an object. This looks to be core difference and where the problem lies.

    function get_row_layout()
    	// vars
    	echo "Get row layout var dump is..." . '<br /><br />';
    	$value = get_sub_field('acf_fc_layout');
    	echo '<br /><br />';
    	return $value;

    Return on subsite:

    Return on subsite

    Return on mainsite:

    Return on mainsite

    Thanks for your help.

  • This reply has been marked as private.
  • This reply has been marked as private.
  • Is the field group in question defined for the sub site or only the site where the posts are created. for ACF fields to work correctly they need to be defined on the current site even if they’re not used there.

  • Thanks John!!! That has solved the issue for me.

  • I am using php 8 and ACF pro, the get_row_layout() and get_sub_field() returning null. Can you please let me know what is the issue?

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

The topic ‘get_row_layout returns empty string when called from subsite’ is closed to new replies.