# NO BUG: after\_loop action does render content before loop

**URL:** <https://forum.bricksbuilder.io/t/no-bug-after-loop-action-does-render-content-before-loop/12093>\
**Category:** Bugs\
**Tags:** v1-8-beta\
**Created:** [May 7, 2023, 8:16pm UTC](https://forum.bricksbuilder.io/t/no-bug-after-loop-action-does-render-content-before-loop/12093 "2023-05-07T20:16:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![neofix](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/n/e9bcb4/32.png) [@neofix](https://forum.bricksbuilder.io/u/neofix)\
**Post date:** [May 7, 2023, 8:16pm UTC](https://forum.bricksbuilder.io/t/no-bug-after-loop-action-does-render-content-before-loop/12093/1 "2023-05-07T20:16:45Z")

</div>

I’m using the loop action as documented, simply changed the ID to the loop-div-ID. However, the echo-ed text is always rendered before my loop content. Is there a mistake on my side or might there be a bug?

```auto
// Perform certain action after the loop of query element my-loop-div-id
add_action( 'bricks/query/after_loop', function( $query, $args ) {
  if ( $query->element_id !== 'my-loop-div-id' ) {
    return;
  }
  echo 'Its working!';
  // $args is an array of the element settings
  // Perform your own logic here

}, 10, 2 );

```

---

<div class="post-metadata">

**Author:** ![aslotta](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/aslotta/32/5419_2.png) [@aslotta](https://forum.bricksbuilder.io/u/aslotta)\
**Post date:** [May 8, 2023, 6:48am UTC](https://forum.bricksbuilder.io/t/no-bug-after-loop-action-does-render-content-before-loop/12093/2 "2023-05-08T06:48:36Z")

</div>

Hey @neofix,

thanks for your report.

This is not a bug though as the `before_loop` and `after_loop` hooks correctly run before / after a query is **executed** , not before / after something is output on the frontend. As the documentation states (see [before](https://academy.bricksbuilder.io/article/action-bricks-query-before_loop/) / [after](https://academy.bricksbuilder.io/article/action-bricks-query-after_loop/)) you can use it to alter the data before / after a query is executed.

> If you are creating a custom query loop or a custom plugin, you might want to perform some additional tasks like setting/resetting specific data before the loop runs.

> If you are creating a custom query loop or a custom plugin, you might want to perform some additional tasks like setting/resetting specific data after the loop runs.

Best,

André

---

<div class="post-metadata">

**Author:** ![neofix](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/n/e9bcb4/32.png) [@neofix](https://forum.bricksbuilder.io/u/neofix)\
**Post date:** [May 8, 2023, 3:12pm UTC](https://forum.bricksbuilder.io/t/no-bug-after-loop-action-does-render-content-before-loop/12093/3 "2023-05-08T15:12:25Z")

</div>

Hi @aslotta  
Thank you for the clarification. Didn’t exactly know it’s only supposed for execution, not outputting content.
