Since the sidebar was being deployed while inside the loop, the
if ( have_posts() ) :
was what was causing it to break. Here’s the fix:
<div id="FL-pest-libray-sidebar">
<?php $category_query_string = new WP_Query(array( 'post_type' => 'page' , 'posts_per_page' => '-1' , 'post_parent' => '413')); while ( $category_query_string->have_posts() ) : $category_query_string->the_post(); ?>
<div <?php
$catspacetitle = get_the_title();
$cattitle = str_replace(" ", "-", $catspacetitle);
echo 'id="',$cattitle,'"'
?> class="FL-pest-cat">
<p <?php
$pcatspacetitle = get_the_title();
$pcattitle = str_replace(" ", "-", $pcatspacetitle);
echo 'id="',$pcattitle,'-title"'
?>class="FL-pest-cat-title"><a href="#"><strong>
<?php the_title(); ?>
</strong></a></p>
<?php
$postid = get_the_ID();
if ($postid == '654') {
$curretnCat="11";}
elseif ($postid == '661') {
$curretnCat="12";}
elseif ($postid == '662') {
$curretnCat="13";}
elseif ($postid == '664') {
$curretnCat="15";}
elseif ($postid == '665') {
$curretnCat="16";}
elseif ($postid == '666') {
$curretnCat="17";}
elseif ($postid == '668') {
$curretnCat="18";}
elseif ($postid == '669') {
$curretnCat="19";}
elseif ($postid == '670') {
$curretnCat="20";}
elseif ($postid == '671') {
$curretnCat="21";}
elseif ($postid == '673') {
$curretnCat="22";}
elseif ($postid == '674') {
$curretnCat="23";}
echo '<div id="pests-cat-',$curretnCat,'"class="FL-pest-indv">';
$query_string = new WP_Query(array( 'post_type' => 'Pests', 'posts_per_page' => '-1' , 'cat' => $curretnCat )); while ( $query_string->have_posts() ) : $query_string->the_post(); ?>
<p <?php
$pestspacetitle = get_the_title();
$pesttitlesearch = array(' ', '(', ')', '.');
$pesttitlereplace = array('-', '', '','');
$pesttitle = str_replace($pesttitlesearch, $pesttitlereplace, $pestspacetitle);
echo 'id="',$pesttitle,'"'
?>class="FL-pest-indv-title"><a href="<?php the_permalink(); ?>"><strong>
<?php the_title(); ?>
</strong></a></p>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>