Getting a PHP warning in my WordPress error log stating: PHP Warning: Illegal string offset 'video_url' in /var/www/html/wp-content/themes/wpeddit-theme-et-child/template-parts/single.php on line 144
This is the line of code it is referring to:
$pl = explode("list=",$meta['video_url']);
To give some context, 'video_url' is a custom field created with Advanced Custom Fields that contains the URL of a YouTube video. In some cases, people submit Playlists instead of individual videos, so this part of the code is handling those cases. This is the section this line of code appears:
case 'video_submissions':
?>
<div class="featurevideo">
<?php
$meta = get_field( 'video_url', $post->ID );
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i',$meta, $match)){
$meta1 = $match;
}
else{
$pl = explode("list=",$meta['video_url']);
if(!empty($pl[1])){
echo '<iframe width="100%" height="auto" src="'.$pl[1].'" frameborder="0" allowfullscreen></iframe>';
}else{
$meta1 = $meta;
}
}
?>
<?php if(!empty($meta1)) {?><?php echo '<iframe width="100%" height="auto" src="https://www.youtube.com/embed/'.$meta1.'" frameborder="0" allowfullscreen></iframe>'; }
?></div>
<?php
break;