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.
Guys this was really helpful, thanks so much!
Really helpful. Any idea why it doesnāt show in the builder?
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.
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.
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!
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!
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