Post content being duplicated by the_content();

I have a query that runs through a set of posts with the post type location. It returns them broken down by a custom field value (in this case, the state in which the location is located). For some reason, just one post is being duplicated on the page. When I use the_content or apply_filters(‘the_content’, $content);, it duplicates that one post. When I use get_the_content, it returns the post content normally, but it doesn’t have the formatting that I need. What in my code could be causing this?

$state_posts = array();

while ($query->have_posts()) {
$state = get_post_meta(get_the_ID(), ‘state’, true);
$state_posts[$state][] = $post;

foreach ($state_posts as $state_post => $state_title) {
<h1 class=”state-name”><?php echo esc_html($state_post); ?></h1>
foreach ($state_title as $listing) {
$post_id = $listing->ID;
$title = get_the_title($post_id);
$content = apply_filters(‘the_content’, get_post_field(‘post_content’, $post_id));
$distance = facetwp_get_distance($post_id);
$distance = (false !== $distance) ? round($distance, 1) . ‘ miles away’ : ”;
$coords = get_post_meta($post_id, ‘location’, true);
<div class=”post-item” data-title=”<?php echo esc_attr($title); ?>” data-latitude=”<?php echo $coords[‘lat’]; ?>” data-longitude=”<?php echo $coords[‘lng’]; ?>” data-distance=”<?php echo $distance; ?>”>
<div class=”post-item-content”>
<h2><?php echo $title; ?></h2>
<div><?php echo $content; ?></div>

Here is the page in question:

And yes, I have checked if anything is odd about the two posts in particular, and they’re formatted exactly the same as all the other posts.

Read more here:: Post content being duplicated by the_content();

Leave a Reply

Your email address will not be published. Required fields are marked *