Custom Query Loop for Image Gallery on Post

Hey bricks fam!

I’ve created a dedicated meta image gallery called “imgal” with Pods.

Now on the post’s page I want to display all the images that I added to the image gallery meta field.

For this, I don’t want to rely on the “Image Gallery” element, because it lacks customizability - but instead do it with a custom query, adding images/blocks that I can fully customize.

Any help is appreciated!

1 Like

I would like to do the same. I’ve asked a couple of times here, but not got any help so far. Please post an answer if you work out how to do this!

Hey @tobi,

how exactly is your custom field set up? There is no native gallery field in Pods, is there? If it’s just a repeatable image field the easiest way is to use a custom query like this:

CleanShot 2024-08-20 at 15.39.41

$pod = pods();

$gallery = $pod->field( [
  'name' => 'post_gallery',
  'output' => 'ids',
] );

return [
  'post_type' => 'attachment',
  'post_status' => 'inherit',
  'post__in' => $gallery,
];

You can then just use the {post_id} on the image element within the query loop.

CleanShot 2024-08-20 at 15.40.51

Best,

André

1 Like

Hi André, @aslotta Thank you for posting that and apologies for hijacking Tobi’s thread.

I just tried that, I changed ‘name’ from your ‘post_gallery’ to ‘member_instruments’ which is the name of my multi Image field in Pods. Could you have a look at the attached photos of how I set up my custom field in Pods because it’s not working, it’s showing all the images in the media library and not just the photos uploaded to my custom field? Many thanks! It would be fantastic to get this working!




Member_instruments_4

Hey @acp693,

the field settings look ok to me. However, you’re using a background image instead of a real image.

Best,

André

Hi, Thank you for answering! I added an image element and removed the background image. Btw, this is on a nestable slider that I’m trying to populate through the query. Unfortunately, the slider is still showing all the images in the media library (around 10 images) and not just the two images I have uploaded to the custom image field. Any further ideas what could be wrong?

Hard to tell without having a look at the actual site… can you maybe share temporary access?

Thanks, but it’s localhost at the moment so I can’t share it. I just tried to set up the problem on a bricks tryout site, but the query editor(PHP) on the nestable slider is missing on the tryout site.

Then I guess you have to figure it out yourself. :smiling_face: Let me know when you found a way to put it online. Then I‘m happy to have a look.

If you do not have access to any kind of server and if you’re using Local feel free to create an export that you can then provide me with. That’s all I can offer for now. :slight_smile:

Hi André, that is a very kind offer. I’m developing on Xampp, I could send you a ‘All in one WP migration’ backup?

That should work as well I guess :slight_smile: Or maybe Duplicator? That is the one I am usually working with…

Thanks for your reply André,

just tested that, with pods gallery meta field on my post type “package”, in my case the meta field is called “packagecontent”.

But it doesn’t seem to do the trick…

Sadly, still displays all media files found on the entire website.

Best,
Tobi

Just wanted to say that the custom PHP solution provided here by aslotta worked for me. :star_struck: