Get all subcategories and related posts

Try using these codes:

if( isset( $sub_category ) ){ 
 echo '<b>more items in: </b>' . $sub_category->name;
 $args = array(
 'cat' => $sub_category->term_id,
 'post__not_in' => array( get_the_ID() )
 );
 $relatedpostsinsubcategory = new WP_Query( $args );
 if( $relatedpostsinsubcategory->have_posts() ){
 while( $relatedpostsinsubcategory->have_posts() ){
 $relatedpostsinsubcategory->the_post();

 ?>
 <a href="https://wordpress.stackexchange.com/questions/324478/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
<?php
 }
 wp_reset_postdata();
 }
}

You can find more information about getting subcategories and related posts here.

error code: 523