How to list post as buch of category, and all of them

here is a general structure how I would do it:

$categories = array(5,2,4,3,1); //manually enter the array of the category ids in the order how you want them to appear
  foreach( $categories as $cat ) { 
    $args = array( 
      'category__in' => array( $cat ), 
      'posts_per_page' => -1
      );
    $cat_query = new WP_Query( $args );
    if( $cat_query->have_posts() ) : while( $cat_query->have_posts() ) : $cat_query->the_post();
//enter here, whatever you want to show per post//
    endwhile;
    endif;
  } //end of foreach

error code: 523