How to print the index number in a query loop

Hello, 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;
}

Just to be clear, the loop completes correctly and returns all the queried objects.

Hi @Kyriakos,

Could you please share the custom query loop? I’m guessing it might have something to do with posts_per_page which you might want to set to -1 explicitly in the query params.

My query looks like this:

I got two elements in the loop element,

image

A text field that calls the function I mentioned

image

and an image element that is displayed correctly for all the queried images

Hi @Kyriakos,

I’m not entirely sure why you’re trying to access the menu_order on a Media post type, but in my case, it always returns 0 for all of my media objects as I didn’t alter this property. Nevertheless \Bricks\Query::get_loop_object(); still returns the objects after 80 objects for me.

Are you trying to print the index number as you’re looping through? If so then you can do something like this:

function get_media_index() {
	$index = intval( Bricks\Query::get_loop_index() ) + 1;

	if ($index) return $index;
}
2 Likes

Yeah using get_loop_index() worked in my case. Thanks.

1 Like

I am trying to do something similar. I am using a Pro Slider from Bricks Xtra and I Want to stagger the even number cards . from a query loop.