I think that your structure here is wrong. I would completely remove your custom query from inside your loop and move it outside. Another option is to make use of other variable names in your custom query and making direct use of the WP_Post
objects
As @Milo already explained, your custom query is most probably affecting the value of your $post
global
OPTION 1
Move the custom query outside your loop (CAVEAT: Untested)
<section class="main-section">
<header>
<h1 class="section-header"><?php the_category("https://wordpress.stackexchange.com/", '', get_queried_object_id() );?></h1>
<ul class="section-nav">
<?php
$cat = get_the_category( get_queried_object_id() )[0];
$categoryPosts = get_posts( array( 'category' => $cat->term_id ) );
foreach($categoryPosts as $post): setup_postdata($post);
?>
<li><a href="https://wordpress.stackexchange.com/questions/173414/<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php unset( $post ); ?>
<?php endforeach; ?>
</ul>
</header>
Then run your loop as normal. the_post()
in your loop will reset your $post
global to the main query
<?php while(have_posts()): the_post();?>
<h2 class="section-blurb"><?php the_title();?></h2>
<div class="info">
<?php the_content(); ?>
</div>
</section>
<?php endwhile;?>
OPTION 2
Use different variable names (CAVEAT: Untested)
<?php while(have_posts()): the_post();?>
<section class="main-section">
<header>
<h1 class="section-header"><?php the_category("https://wordpress.stackexchange.com/");?></h1>
<ul class="section-nav">
<?php
$cat = get_the_category()[0];
$categoryPosts = get_posts(array('category' => $cat->term_id));
foreach($categoryPosts as $categoryPost):
$title = apply_filters( 'the_title', $categoryPost->post_title ); ?>
<li>
<a href="https://wordpress.stackexchange.com/questions/173414/<?php the_permalink();?>">
<?php echo $title; ?>
</a>
</li>
<?php endforeach; ?>
<?php unset( $categoryPost ); ?>
</ul>
</header>
<h2 class="section-blurb"><?php the_title();?></h2>
<div class="info">
<?php the_content(); ?>
</div>
</section>
<?php endwhile;?>