I am working on a WordPress website, and I am having trouble with the for each loop. Everything looks right, only it's giving me this error on my web page: Warning: foreach() argument must be of type array|object
<?php
get_header();
while (have_posts()){
the_post(); ?>
<div class="page-banner">
<div class="page-banner__bg-image" style="background-image: url('<?php echo get_theme_file_uri('images/connection.jpg') ?>');"></div>
<div class="page-banner__content container container--narrow">
<h1 class="page-banner__title"><?php the_title(); ?></h1>
</div>
</div>
</div>
<div class="container container--narrow page-section">
<div class="metabox metabox--position-up metabox--with-home-link">
<p><a class="metabox__blog-home-link" href="<?php echo
get_post_type_archive_link('event'); ?>"
><i class="fa fa-home" aria-hidden="true"></i> Events Home</a>
<span class="metabox__main"><?php the_title(); ?></span></p>
</div>
<div class="generic_content"><?php the_content(); ?></div>
<?php
$dcHosts = get_field('event_host');
foreach($dcHosts as $companies) {
echo get_the_title($companies);
}
?>
</div>
<?php }
get_footer();
?>