Link on post title only if post have content

Based on this question

Probably the easiest way would be:

<?php
// The Loop
while (have_posts()) : the_post(); ?>

    <?php if ('' !== get_post()->post_content): ?>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark"
               title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php else: ?>
        <h2><?php the_title(); ?></h2>
    <?php endif; ?>
    <div><p>
            <?php if (get_field('telefono')): ?>Telefono: <?php the_field('telefono'); ?>
            <?php endif; ?>

            <?php if (get_field('email')): ?> Email <?php the_field('email'); ?>
                <br/>
            <?php endif; ?>
            <?php if (get_field('indirizzo')): ?> Indirizzo: <?php the_field('indirizzo'); ?>
                <br/>
            <?php endif; ?>
            <?php if (get_field('link_mappa')): ?>
                <a href="<?php the_field('link_mappa'); ?>" target="_blank" rel="noopener noreferrer"> <img
                            src="https://www.mondosup.it/wp-content/uploads/link_mappa_scuole_sup.png" width="250"/></a>
            <?php endif; ?>
        </p>
    </div>

<?php endwhile;

else: ?>
    <p>Sorry, no posts matched your criteria.</p>


<?php endif; ?>
    </div>
    </section>


<?php get_sidebar(); ?>
<?php get_footer(); ?>