WordPress shortcode for a section Template

I have found the Solution with another Code but still not know what was the Problem with the First Code . It is solved . the Code which I will use will be :

               <div class="card-deck">
               <?php 
               // the query  
               $wpb_all_query = new WP_Query(array(
                                  'post_type'=>'grants',
                                  'scholarship_degree'=> 'bachelor',
                                  'post_status'=>'publish',
                                  'posts_per_page'=>  4,
                                  'tax_query' => array(array(
                                    'taxonomy' => 'expired',
                                     'field'    => 'slug',
                                     'terms'    => array( 'expired' ),
                                     'operator' => 'NOT IN',
                                    )),
                                )); 
            ?> 
            <?php if ( $wpb_all_query->have_posts() ) : ?>
                  <!-- the loop -->
               <div class="row">           
                    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
                       <div class="col-sm-3" > 
                           <a href="https://wordpress.stackexchange.com/questions/362743/<?php the_permalink(); ?>">
                             <div class="card">
                              <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), ' ' ); ?>
                              <img  class="card-img-top" src="<?php echo $url ?>" /> 
                                  <div class="card-body">
                                    <p class="card-title"><?php the_title();?> </p>
                                         </a>
                                          <p class="card-text">
                                        <div class="text-muted">
                                    <p><?php $terms = wp_get_post_terms($post->ID, 'funding-scholarship');
                                              if ($terms) {
                                              $out = array(
                                              'name'=>' 
                                                  <svg class="bi bi-bookmark" width="1em" height="1em" viewBox="0 0 16 16"                                                                          fill="black"xmlns="http://www.w3.org/2000/svg">
                                                   <path fill-rule="evenodd" d="M8 12l5 3V3a2 2 0 00-2-2H5a2 2 0 00-2 2v12l5-3zm-4 1.234l4-2.4 4 2.4V3a1 1 0 00-1-1H5a1 1 0 00-1 1v10.234z" clip-rule="evenodd"/>
                                                  </svg> تمويل المنحة     ');
                                  foreach ($terms as $term) {
                                  $out[] = '<a class="text-muted' .$term->slug .'" href="' .get_term_link( $term->slug, 'funding-scholarship') .'">' .$term->name .'</a>';}
                                   echo join( ', ', $out ); }?></small></p> 
                          </div>  
                      </div>  
                  </div>
               </div>  
                  <?php endwhile; ?>
                  <!-- end of the loop -->
                  <?php wp_reset_postdata(); ?>
                  <?php else : ?>
                  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> 
                  <?php endif; ?>  
                  </div>  
                  </div> 


          AND THE SHORTCODE WHICH I WILL USE :
          function my_bachelor_shortcode( $attr ) {
                       ob_start();
                       get_template_part('frontpage/section', 'bachelorscholarships');
                      return ob_get_clean();
          }
          add_shortcode( 'bachelorgrantslist', 'my_bachelor_shortcode' );