What's wrong with the code wordpress?

Notice: Undefined offset: 1 in /home/b/btrainlb/wp.obgames.ru/public_html/wp-includes/class-wp-query.php on line 3252
Notice: Trying to get property of non-object in /home/b/btrainlb/wp.obgames.ru/public_html/wp-content/themes/obgames/index.php on line 179 of the business game
Given that this error (above).
There is here such code:
<?php the_post(); if (has_post_thumbnail()): ?>
 <img src="<?php the_post_thumbnail_url(); ?>" alt="Event">
 <?php else: ?>
 <div class="sbox__video-wrapper"> 
 $image = get_the_post_thumbnail_url($post->ID, 'medium'); // Same line 179
 $title = 'business game' . get_the_title();
 if (!$image) $image = get_template_directory_uri() . '/img/no-image.jpg';
 echo "<img src='$image' alt='$title'>"; 
 <?php endif; ?>

What's wrong? Why produces an error?
April 7th 20 at 15:41
4 answers
April 7th 20 at 15:43
It is necessary to look in this variable.
In the code there is a reference to the item $post->id, which is not, and that is swearing.
April 7th 20 at 15:45
You need to disassemble that function returns get_the_post_thumbnail_url()
And that she needed to pass as an argument, it seems to me that it is sufficient, only the id of the post $post->ID

It is logical to think that this function rips image url of page(post). Maybe this is an old function WP which is used in a template topic, it may not. Check and do the dumps.
April 7th 20 at 15:47

April 7th 20 at 15:49
Inside the loop you do not need to pass ID of the post, he is automatically taken into account.
$image = get_the_post_thumbnail_url($post->ID, 'medium');
do a simple $image = get_the_post_thumbnail_url('medium');

Find more questions by tags PHPWordPress