How to access the Parent post ID in a nested/child loop? (Using metabox)

Hi, I have been searching all over but can’t find an answer.

I have a loop successfully querying posts from a custom post type.

Inside the parent loop is a nested loop successfully querying gallery images from an Image Advanced field (Metabox).

I am using Lightbox, and would like each post gallery to only show it’s own images in the modal.

For this I need the parent post’s ID or slug to create a unique group name for each gallery.

How do I access the parent post object for this data? Using something like {post-id} returns the current child loop ID’s.

Thanks in advance.

Responding to my own post…

Here is what I did for the lightbox galleries to function independently:

Added a function to my code snippets:

function HLS_current_query_id() {
	global $bricks_loop_query;

	if ( empty( $bricks_loop_query ) ) {
		return false;
	}

	$current_query_id = \Bricks\Query::is_any_looping();

	return $current_query_id;

}

Then I could use the query ID as the unique identifier in the lightbox of each child query:

The query ID returned is not the actual parent loop’s post ID or slug as I initially wanted, but it is still unique for each child loop and does the job with the least amount of code.

I got my inspiration from this useful resource: https://itchycode.com/bricks-builder-useful-functions-and-tips/

Hopefully this can help someone looking for the same functionality or inspire an even better solution.

It would be most useful however if {parent_id} becomes available as a dynamic tag in Bricks. :slight_smile: