You have assigned the queries result inside the first condition. So the values assigned to this variable “cm_offerta_post_figli” won’t be accessible inside the second elseif condition.
Please put the below code on the top of First condition. It will work.
<?php $cm_offerta_post_figli = new WP_Query( array(
'post_type' => 'cm_offerta',
'post_parent' => get_the_ID(),
'order' => 'ASC',
)
); ?>
I have modified your code as below, perhaps it will help:
<?php $cm_offerta_post_figli = new WP_Query( array(
'post_type' => 'cm_offerta',
'post_parent' => get_the_ID(),
'order' => 'ASC',
)
); ?>
<?php if ( $args['tipologia'] == 'lista' ) : ?>
<!-- First Loop Option -->
<?php if ( $cm_offerta_post_figli->have_posts() ) : ?>
<ul class="list-group list-group-flush ms-0">
<?php while ( $cm_offerta_post_figli->have_posts() ) : ?>
<?php $cm_offerta_post_figli->the_post(); ?>
<li class="list-group-item"><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<!-- END of First Loop Option -->
<?php elseif ( $args['tipologia'] == 'descrizione' ) : ?>
<!-- Second Loop Option -->
<?php if ( $cm_offerta_post_figli->have_posts() ) : ?>
<div class="bg-light row row-cols-1 row-cols-md-2 mb-5 p-5">
<?php while ( $cm_offerta_post_figli->have_posts() ) : ?>
<?php $cm_offerta_post_figli->the_post(); ?>
<div class="col">
<div class="card bg-transparent border-0">
<div class="card-body">
<h3 class="card-title"><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
<!-- END of Second Loop Option -->
<?php else : ?>
Errore
<?php endif; ?>
<?php wp_reset_query(); ?>