I have created a custom post type with a relationship connected to another custom post type.
Inside a query I have a count for the relationship field to show the total number of posts that have been selected. I thought at first it was working fine until I remove a post from the relationship and it still shows 1 instead of 0
$posts = new WP_Query(
array(
'post_type' => 'group-clients',
'post_status' => 'publish',
'orderby' => '',
'order' => 'asc'
)
);
$posts = $posts->get_posts();
if ($posts) {
foreach( $posts as $post ) { ?>
<div class="p-4">
<?php the_title() ?>
</div>
<div class="p-4">
<?php
$properties = count( (array) get_field('properties') );
if($properties) {
echo $properties;
} else {
echo '0';
}
?>
</div>
<?php
}
}
wp_reset_postdata();
Can anyone work out why?