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.
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.
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;
}