Search code examples
phphtmlundefinedoffset

Please assist me in resolving an Undefined offset: 0 in /public_html/wp-content/themes/modus-child/functions.php on line 51


I have inherited a problematic website after communication broke-down with their original web developer.

I have been working through and resolving as many errors as possible.

PHP Notice: Undefined offset: 0 in /home/customer/www/public_html/wp-content/themes/modus-child/functions.php on line 51

The long term goal will be to re-build the website, using a different theme, but I would appreciate some help in resolving this error to give us a safety net while the development is taking place.

Screenshot showing the code as pasting the code didn't look right

here is line 46 onwards Line 51 is the line that begins with if($featured[0]=="Featured"){ I can see the offset 0 in brackets.

$count=0;
      foreach ($woo_catgery as $sc) {
            $count++;
            if($count==6){continue;}
            $featured = get_field('featured', $sc->taxonomy . '_' . $sc->term_id);
            if($featured[0]=="Featured"){
            $thumbnail_id = get_term_meta( $sc->term_id, 'thumbnail_id', true );
            $image_url=wp_get_attachment_url( $thumbnail_id ); 
            if(!empty($image_url)){
                $image_url=$image_url;
            }else{$image_url=get_stylesheet_directory_uri().'/img/blank.png';}
            $link = get_term_link( $sc->slug, $sc->taxonomy );
            $hm .='<li>
                    <div class="cat_image">
                        <a href="'. $link .'" title="" target="_self">        
                            <img alt="icon" src="'.$image_url.'">
                        </a>                    
                    </div>
                    <div class="cat_bx_cnt">
                        <div class="cat_ttl">
                            <h3 class="cat_ttl_mn">'.$sc->name.'</h3>                      
                        </div>
                        <a class="link-more" href="'. $link .'" title="" target="_self">
                            <i class="fa fa-angle-right" aria-hidden="true"> </i>
                        </a>
                    </div>
                </li>               
            '; 
            }
      }
      $hm .='</ul>';
      return $hm;
    
}
add_filter( 'woocommerce_marketing_menu_items', '__return_empty_array' );

add_action( 'after_setup_theme', 'remove_pgz_theme_support', 100 );

function remove_pgz_theme_support() { 
remove_theme_support( 'wc-product-gallery-zoom' );
}

Solution

  • $featured seems to be an empty array so you should first check if it contains elements:

    if(count($featured) > 0 && $featured[0]=="Featured")