NO BUG: after_loop action does render content before loop

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?

// 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 );

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 / after) 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é

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