Media query and Nestable slider (acf/ JetEngine gallery field)

Thanks, i try but this donā€™t work, i have error:
Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array

I see that JetEngine Media ID is type of string. In that case your code is okay. Iā€™ve updated mine with use of explode and array_map.

1 Like

Guys this was really helpful, thanks so much! :star_struck:

Really helpful. Any idea why it doesnā€™t show in the builder?

1 Like

Itā€™s in the Oxygen & Breakdance builders. Simple stuff like this is what makes me question Bricks sometimes. Powerful builder for everything but the obvious stuff.

2 Likes

If you want to use this query for different elements, a cleaner way might be to target a class or a data attribute instead of specific IDs.

1 Like

Good point.

Youā€™d update the ID part of it to the data-attribute to do that?

Is there any chance to customize the code for the JE gallery field set to Media URL?

TIA
Goran

Thanks @MartinWB !

Your code works fine! :wink:

1 Like

Hello guys, not sure if someone tries to use gallery field from option pages using jetengine. Here is solution for you. Cheers

(gallery field set to Media ID)

$gallery = jet_engine()->listings->data->get_option( 'option-slug::gallery-field-name' );

if(!empty($gallery)) {
  
$images = explode(",", $gallery);
$galleryArray = array_map('intval', $images);

return [
    'post_type'      => 'attachment',
    'post_mime_type' => 'image',
    'post_status'    => 'inherit',
    'orderby'        => 'post__in',
    'post__in'       => $galleryArray,
    'posts_per_page' => -1,
]; }

else {
  	return [];
}

Hey guys,

I canā€™t get this to work for a gallery field within a group - my ACF knowledge is fairly limited so itā€™s likely I am botching the snippet.

Itā€™s a bit shocking that this isnā€™t a feature given Bricks proudly talks about itself as ā€œThe most advanced dynamic data solutionā€ where you can ā€œPopulate your content without limitations.ā€

@aslotta Andre I have tried to amend your bricks/posts/query_vars hook snippet to look for the sub-field within a group, but I think there may be more to do before we can loop it. Do we need to get the group and then define the sub-fields beforehand?

Any help appreciated!

2 Likes

Hi! I canā€™t understand why it doesnā€™t work for me. I change your code to query a pdf files

$gallery = get_post_meta( get_the_ID(), 'dokumenty', true);

if(!empty($gallery)) {
  
$images = explode(",", $gallery);
$galleryArray = array_map('intval', $images);

return [
    'post_type'      => 'attachment',
    'post_mime_type' => 'application/pdf',
    'post_status'    => 'inherit',
    'orderby'        => 'post__in',
    'post__in'       => $galleryArray,
    'posts_per_page' => -1,
]; }

else {
  	return [];
}

Itā€™s works if I remove ā€˜post__inā€™, query returns all pdf files, but nothing with ā€˜post__inā€™ => $galleryArray. I use the same JetEngine gallery field with media ID value format.

@TomLD, I was having the same issue, ChatGPT says:

To make the snippet work when the field is within a group in ACF, you need to modify it to access the gallery field correctly from the group. ACF stores group fields as an associative array, so you need to retrieve the group first, and then access the gallery field within it.

Hereā€™s the updated code:

// Retrieve the group field first
$service_gallery = get_field('service_gallery');

// Check if the group field and gallery field exist
if (!empty($service_gallery) && !empty($service_gallery['service_gallery_images'])) {
    $acf_images = $service_gallery['service_gallery_images'];
    
    return [
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'post_status' => 'inherit',
        'orderby' => 'post__in',
        'post__in' => $acf_images,
        'posts_per_page' => -1,
    ];
} else {
    return [];
}

This resolved the issue for me :slight_smile:

1 Like