• Hello,

    I am getting this error:TRYING TO GET PROPERTY ‘SLUG’ OF NON-OBJECT when running the following snippet that’s a Search function on my site:

     while (have_posts())
          {
             the_post();
             $crumbs = array();
             $ptype = 'page';
             $rank = $i;
             $source = get_field('source',$post->ID);
             $pdate = get_the_date();
             $ptitle = get_the_title();
             $url = get_the_permalink();
             $catinfo = get_the_category();
             
             // boost direct hits on title 
             if (strpos(strtolower($ptitle),strtolower($terms)) !== false) $rank -= 200;
             
             // boost by keyword
             $keywords = get_field('search_keywords',$post->ID);
             if (trim($keywords))
             {
                $keymatch = 0;
                $data = explode(',',strtolower($keywords));
                foreach ($data as $keyword)
                {
                   if (trim($keyword) == strtolower($terms)) $keymatch++;
                }
                if ($keymatch) $rank -= 400;
             }
             
             // check against filters
             $filtered = 0;
             foreach ($url_filter as $key)
             {
                if (strpos($url,$key) !== false) $filtered++;
             }
             
             // news get own category and publication date
             if ($catinfo[0]->slug == 'news') 
             {
                $ptype = 'news';
                $pdate = get_the_date();
             }
    ...

    It happens on the line `if ($catinfo[0]->slug == 'news')

    Any reasons why this is happening? Thanks,

    • This topic was modified 1 year, 6 months ago by bcworkz. Reason: No all caps please
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Trying to Get Property ‘slug’ of Non-object’ is closed to new replies.