I have a custom category template which was working correctly, showing 6 different category posts. After I added two new categories, all went berserk and 2 category pages are showing incorrectly filtered posts even though all category pages still show the correct category title in the H1. I am using template parts for several html blocks.
Where could I start checking for errors?
I also noticed with
$category = get_the_category('');
var_dump($category);
that one of the categories now has a category parent, which I might have erroneously selected, but deselecting it apparently did not fix the relationship.
This is my main category post template:
<?php
$category = get_the_category();
$catTerm = $category[0]->cat_name;
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'featured' => 'featured',
'post_status' => 'publish',
'category_name' => $catTerm
);
$lastPost = new WP_Query($args);
if( $lastPost->have_posts() ):
echo '<div id="mainArticleBox">';
while( $lastPost->have_posts() ): $lastPost->the_post();
// get_template_part('content', 'featured-big');
if (has_post_thumbnail()) :
$category = get_the_category( $id );
echo '
<div class="hero-img" style="background-image: url('
. get_the_post_thumbnail_url() .
');">
<div class="tag-id hidden-xs hidden-sm">';
$category = get_the_category();
echo '<a href="'.get_category_link($category[0]->cat_ID).'">' . $catTerm. '</a>
</div>
</div>
';
echo '
<div class="mainArticle-texts">
<h1 class="h1"><a href="' . get_permalink() . '">' . get_the_title(). '</a></h1>
<div class="excerpt"><a href="' . get_permalink() . '"> <span>' . excerpt(30) . '</span> </a></div>
</div>
</div>';
endif;
endwhile;
endif;
?>