7th Jan '23
/
3 comments

Loop Item ID and Loop Item Object in Bricks

If you are working on a Bricks site with specific requirements, chances are you need to grab the ID and/or object of the current item (post/term/user) in the loop when using a Query Loop.

We used the following in several tutorials already on the site but just posting these here as a separate topic for easy reference.

Loop Item ID

\Bricks\Query::get_loop_object_id()

To show it as a dynamic data tag in a text element, register a function:

function bl_get_loop_item_id() {
	return \Bricks\Query::get_loop_object_id();
}

and

{echo:bl_get_loop_item_id}

Loop Item Object

\Bricks\Query::get_loop_object()

To see all the properties of the object:

print( '<pre>' . print_r( \Bricks\Query::get_loop_object(), true ) . '</pre>' );

Reference

https://itchycode.com/bricks-builder-useful-functions-and-tips/

Get access to all 612 Bricks code tutorials with BricksLabs Pro

3 comments

  • Hello, Sridhar,

    Thank you kindly for your code, it has worked perfectly.

    Best regards, Lukas @ webarch.lt

  • I'm calling the following function in a custom query loop to get a post's media index but for some reason it stops returning the object after 80 objects, any idea why?

    function get_media_index(){ $img = \Bricks\Query::get_loop_object(); if($img) return $img->menu_order; }

Leave a Reply to Kyrill (Cancel Reply)

 

Related Tutorials..

How to display a Query Loop in 3 columns in Bricks

How to display a Query Loop in 3 columns in Bricks

This tutorial provides the builder settings and CSS codes that can be pasted in order to create a 3-columns query loop container inside Bricks Builder.
Categories:
Pro
Excluding Duplicate Posts from Query Loops in Bricks

Excluding Duplicate Posts from Query Loops in Bricks

How to ensure that posts are not duplicated when two query loops are used on the same page.
Categories:
Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements:
Pro
Post Views Counter Query Loop in Bricks

Post Views Counter Query Loop in Bricks

How we can output the most viewed posts in your Bricks site in a query loop.
Categories:
Pro
Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Updated on 29 Feb 2024 In the Sibling Terms Bricks Query Loop tutorial, a member asked: How can I set the class "active" to the…
Categories:
Adding any Custom WP_Query loop to Bricks’ Query Loop

Adding any Custom WP_Query loop to Bricks’ Query Loop

Sometimes we may need to create a custom post loop using Bricks' query loop feature, but wish to use our own WP_Query code for more…