Home Forums General Issues Variables, Repeater & Flexible Content Issue


Variables, Repeater & Flexible Content Issue

  • Hi,

    I have a slightly complicated setup which works as follows:

    Repeater Field
    — Choose BG Color
    — Choose BG Image
    —- Flexible Content
    —— Layouts (Full page width, 50/50 page width etc)

    I am storing the background image into a variable like so:

    <?php if(get_sub_field('section_background_image')) { 
       $bgImg = get_sub_field('section_background_image'); 
    }; ?>

    Then calling it like so:

    <?php if( isset($bgImg) ) { ?>
       <img class="section-bg-img" src="<?php echo $bgImg ?>" />								
    <?php } ?>

    But the image does not display. If I place the code before the flexible content row loop, it appears, but not within.

    Here is a copy of my code:

    Thanks in advance

    Attached is my export.

  • When you create the field type “image” you have to choose the return value: Image URL

    Why is that? Because if the default value is set to “Image Object”, that return an array of values that contains a bunch of info about the image, like: url, width, height, size etc.. but when you set to Image URL then will return the full path of your image: e.g.

    If you want more information about the image field type, you can check through here:


  • I am currently using ‘image URL’ for the display of my image.

    Thanks for your help.

  • Is this happening only with this field? The others fields are returning some content?

  • All other fields are working fine.

    Here is my code:

  • Yeah, i think i found the error, you have 2 Repeaters alright, soo you are saving the variables on the first repeat, you have to put on the second repeat, below the line 22 on the pastebin. Because on the first repeat the field that you trying to get doesn’t exist, only on the second.

  • I guessed this may be an issue, to use a sub field from the first repeater, inside the second… but I’ve tried to store it within a variable to use further down the code. This does not work.

    There has to be a workaround?

  • You can’t get the value of a field on the second repeater to the first, but you can send the value of the field on first repeater to the second. This should work, just as you did.

    Link a picture of the configuration fields, on the backend.

  • Screenshot attached.

    My configuration is – Repeater field, Background colour, & image, Flexible Content.

  • Ok, lets check somes things, try change the name of the flexible_content, the name “row” may be getting in conflict with something.

    Check if the “<?php if( get_row_layout() == ‘full_width_row’ ): ?>” have the correct name of the field, maybe its working but the “if” is blocking.

  • full_width_row is correct, I have just double checked.

    If I change my flexible field from ‘row’ to something else, will I lose all my data? I have pages of it!

  • Yeah, you will lose. Do a backup of the stuff first.

  • I will create a backup, rename the flexible content field and report back as soon as possible. It may not be today though.

    Thank you so much for your replies today, you’ve been a great help. Hopefully, we can figure this out soon!

    I’ll respond as soon as I can.

  • Hi,

    I have removed the ‘row’ flexible content field and created a new one labelled it as something completely different but it gave the exact same results, so that rules that out.

    I’m at a loss on ideas. I may have to re-think how the backend is setup.

  • Ok, after the all tests we’ve done and no result was made i went to my wordpress to test your code, the result was the code worked smoothly, nothing wrong.
    Here is the result picture:

    So maybe it’s the way your doing wrong, in my case i create a page and then create i file on my theme with the ID of the page, e.g. page-7.php, there i put your code.

    On the configuration fields, i linked the fields to that page, nothing different and then your code i just changed the “row” to “row-flexible”.

    I’m sending 2 files: the first one is the .json with my configuration fields, the second is the page-7.php.

    How is the way that you are doing?

    Edit: You can of course set your code on the page.php normally but you can also create a “page template” and then set it on the configuration of the page. The last option is closer to the professional way. =D

  • Thank you ever so much. I will take a look at this and reply as soon as possible.

    Can you confirm that the images are showing for you? After a quick go, I still can’t get them to work?

    I’m using V4 if that makes a difference? Perhaps V5 would work better?

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

The topic ‘Variables, Repeater & Flexible Content Issue’ is closed to new replies.