@localhost3310

Из за чего ошибка Notice: Trying to get property of non-object in?

Я получаю такие ошибки
Notice: Trying to get property of non-object in /home/httpd/vhosts/museum.binarywd.com/httpdocs/platforms/themes/blankslate/rss-collections.php on line 48

Notice: Trying to get property of non-object in /home/httpd/vhosts/museum.binarywd.com/httpdocs/platforms/themes/blankslate/rss-collections.php on line 49

Notice: Trying to get property of non-object in /home/httpd/vhosts/museum.binarywd.com/httpdocs/platforms/themes/blankslate/rss-collections.php on line 50


От этого кода
if ($kinoafisha->have_posts()) : while ($kinoafisha->have_posts()) : $kinoafisha->the_post();
    // $category = get_the_category();
    // $category2 = get_the_terms($post->ID, 'rubcollection');
    // foreach ($category2 as $cat2) {
    //     $current_cat_id = $cat2->term_id;
    //     $current_cat_name = $cat2->name;
    //     $current_cat_slug = $cat2->slug;
    // }
    
    // $category = get_queried_object($post->ID, 'rubcollection');
    // echo $current_cat_id = $category->term_id;
    // echo $current_cat_name = $category->name;
    $category = get_the_terms($post->ID, 'rubcollection');
    $current_cat_id = $category[0]->term_id;
    $current_cat_name = $category[0]->name;
    $current_cat_slug = $category[0]->slug;

        
    echo '<pre>';
var_dump($category);
echo '</pre>';

    // create an array if there is more than one result
    $kinoafishaid = array();

    // Add in your custom fields or WP fields that you want
    $kinoafishaid['name'] = get_the_title();
    $kinoafishaid['link'] = get_the_permalink();
    $color = get_field( 'type_afisha' );
    $kinoafishaid['type_afisha'] = get_field('type_afisha');
    $imagev = get_field('img');
    $kinoafishaid['img'] = !empty($imagev) ? $imagev['url'] : '';
    $baner = get_field('baner');
    $kinoafishaid['baner'] = !empty($baner) ? $baner['url'] : '';
    $kinoafishaid['description'] = str_replace('<?xml encoding=\"utf8\" ?>" ', '', get_field('mobile'));
    $images = get_field('gallery');
    $kinoafishaid['gallery'] = $images;
    $kinoafishaid['inform'] = str_replace('<?xml encoding=\"utf8\" ?>" ', '', get_field('inform'));
    $kinoafishaid['autor'] = get_field('autor');
    $kinoafishaid['time'] = get_field('time');
    $kinoafishaid['material'] = get_field('material');
    $kinoafishaid['razmeri'] = get_field('razmeri');
    $kinoafishaid['number'] = get_field('number');
    $kinoafishaid['legend'] = str_replace('<?xml encoding=\"utf8\" ?>" ', '', get_field('legend'));
    $kinoafishaid['fond'] = get_field('fond');


    //$kinoafishaid['short_desc'] = get_sub_field('short_desc');

    // $kinoafishaid['price'] = get_sub_field('price');

    // $kinoafishaid['mesto_sobitiya'] = get_sub_field('price');

    //  $kinoafishaid['acters_sostav'] = get_sub_field('acters_sostav');





    $afishaArr[] = $kinoafishaid;

endwhile;

endif;


А именно из последних 3 строчек
$category = get_the_terms($post->ID, 'rubcollection');
    $current_cat_id = $category[0]->term_id;
    $current_cat_name = $category[0]->name;
    $current_cat_slug = $category[0]->slug;


Скрин страницы https://i.imgur.com/6gCMdRq.png

Помогите пожалуйста решить проблему
  • Вопрос задан
  • 157 просмотров
Решения вопроса 1
Kozack
@Kozack Куратор тега WordPress
Thinking about a11y
Trying to get property of non-object
Вы пытаетесь прочитать свойство переменной, которая не является объектом (а например массивом или чем-то другим)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы