Moritz Reitz
← Back to blog
Meta Box ProWeb Development

Display Meta Box Io advanced image field in Oxygen repeater

A tutorial on how to display an Image Advanced field from a Meta Box clonable group field inside an Oxygen Builder repeater using a PHP function workaround.

27 April 2024 · Moritz Reitz

I recently came across an issue where I was trying to use an advanced image field from Meta Box inside an Oxygen Builder repeater. However, after I selected the dynamic data values in Oxygen the field was not displaying. Oxygen Builder support made clear that this was an existing issue and that it needed a workaround as they did not know when it would get fixed.

Therefore I thought I might share my solution here in a step-by-step tutorial in case you are having the same issue.

Create the Meta Box Pro fields

1. Create a Meta Box Pro ‘group’ field for your post type

Make sure the ‘Group’ field is clonable, this allows you to populate the filed group on the post.

2. Create an ‘Image Advanced’ field

Once you have created the Group field in step one you need to add an ‘Image Advanced’  inside the Meta Box Group field. Remember the ID you named the ‘Advanced Image’ field. In our example, the id is 'section_image'.

Add the custom code

According to Oxygen support, you can use global ‘$meta_box_current_group_fields;’ to get the current group inside the Oxygen Repeater.

Therefore I created the following function and added it with the Code Snippets plugin to the functions.pho: 

function get_oxygen_repeater_section_image_id() {
    global $meta_box_current_group_fields;

    // Replace ‘section_image’ with your image field ID
    $image_id = $meta_box_current_group_fields[‘section_image’][0];

    return $image_id;
}

Make sure you replace the image ID ‘section_image’ with your own image ID. Once you are done save and activate the snippet. 

Query the image ID in the oxygen repeater

Set up the repeater

Select ‘Query’ in the repeater settings, tick the ‘Use Meta Box Group’ box and select your Meta Box Group field below.

select meta box aio group field in oxygen builder
select meta box aio group field in oxygen builder

Add the image element

Drag the image element inside the repeater element. Select ‘Media Library’ in the primary settings of the image element.

Query the image ID

  1. Select the ‘data’ option inside the ID field. 
    add dynamic meta box data to oxygen repeater
  2. Select ‘PHP Function Return value’ and the advanced dynamic data settings
    select ‘php function return value’ und the advanced dynamic data settings
  3. Insert the name of the function we previously created: ‘get_oxygen_repeater_section_image_id’
    enter function name calling meta box aio field

Save your edits, clear the cache and reload the page. The image from your Meta box group field should display now.

This workaround has been stable across multiple projects. The Meta Box Image Advanced field documentation covers the available field options in detail. If you're working with Meta Box and need help with more complex field relationships, my post on querying reordered Meta Box posts in Bricks Builder covers a related use case. For bespoke WordPress plugin development or other custom web development work, feel free to get in touch.

FAQ

Why doesn't the Meta Box Image Advanced field display inside an Oxygen Builder repeater? This is a known compatibility issue between Meta Box and Oxygen Builder. Oxygen's dynamic data system doesn't natively handle the Image Advanced field type inside a repeater when it's part of a cloneable group. The workaround is a small PHP function that reads the `$meta_box_current_group_fields` global to retrieve the image ID, which you then call via "PHP Function Return Value" in Oxygen's dynamic data settings.
Is this workaround stable across Meta Box and Oxygen Builder updates? The `$meta_box_current_group_fields` global has been stable across versions and I've used it on multiple projects without issues. That said, always test after updating either plugin. If Oxygen ever adds native support for Image Advanced fields in repeaters, the workaround can be removed — it won't break anything if left in place.
Can I use the same technique for other Meta Box field types, not just Image Advanced? Yes. The `$meta_box_current_group_fields` global gives you access to all fields in the current cloneable group iteration. Adapt the function to return text, a URL, or any other value by changing the array key and return type. The only requirement is that the group field is set to "clonable" in Meta Box — the global only populates inside a clonable group context.

Work with me

Found this helpful?

Get in touch if you need help with your website, SEO, or paid advertising — I offer a free initial consultation.