After having a Wordpress website moved from one environment to another (a test of migration from staging to dev to ensure no errors), everything works fine except for a While loop on custom blog templates. This loop work just fine on one environment, but after moving to another, the page stops working at the While loop.
Interestingly, when I remove the variables from the While, the page works, but of course my blog cards are blank except for the title. I'm at a loss as to what could be causing this to work fine in one place, and break in another. After going over it several times I can't seem to determine where an error might occur, or why.
<div class="content-blog">
<div class="loader"></div>
<?php
$count = 0;
$args = array(
'post_type' => 'blog',
'orderby' => 'date',
'posts_per_page' => 10,
'post_status' => 'publish',
);
//our blog query
$query = new WP_Query( $args );
if ( $query->have_posts() ) { ?>
<div class="band">
<?php while ( $query->have_posts() ) : $query->the_post();
$post_count = $query->post_count;
$all_posts = $query->found_posts;
$category = get_the_terms( $id, 'blog_category' );
$count++;
// Finds every 5th item and gives it item-1 string to add as class
$size = $count % 5 === 0 ? 'item-1' : 'item-2';
// Gets the post content so we can trim its size for a custom excerpt
$content = get_the_content();
// Trims the post content to 175 characthers
$content_count = mb_strimwidth($content, 0, 175, '...');
// If it is a large blog card add a few more characthers
if ($count % 5 === 0) {
$content_count = mb_strimwidth($content, 0, 225, '...');
}
?>
<div id="post" class="<?php echo $size; ?>" data-offset="<?php echo $post_count; ?>" data-total="<?php echo $all_posts; ?>">
<a href="<?php the_permalink(); ?>" class="card">
<div class="thumb" style="background-image: url(<?php the_post_thumbnail_url();?>);"></div>
<article class="<?php echo $category[0]->slug; ?>">
<h1><?php the_title(); ?></h1>
<p style="margin-top: 10px;">
<?php echo $content_count; ?>
</p>
<span><?php echo $category[0]->name; ?></span>
</article>
</a>
</div>
<?php endwhile;
wp_reset_postdata(); ?>
<?php
} ?>
</div>
</div>