-1

This is the error I am getting in the widget area I have defined for my language switcher:

NOTICE: UNDEFINED INDEX: CODE IN /HOME/DUTCHTAX/DOMAINS/DUTCHTAXADVICE.NL/PUBLIC_HTML/WP-CONTENT/THEMES/PATTI/FUNCTIONS.PHP ON LINE 835 EN

// Language Switcher for WPML
if (!function_exists('delicious_language_selector')) {
    function delicious_language_selector() {
        if (function_exists('icl_get_languages')) {
            $languages = icl_get_languages('skip_missing=0&orderby=code');
            wp_enqueue_script( 'dt-tipsy' );
            wp_enqueue_style( 'dt-tipsy' );
            if(!empty($languages)){
                echo '<div id="header_language_list"><ul>';
                    foreach($languages as $l){
                        if($l['active']) { echo '<li class="active-lang switch-lang" original-title="'.$l['native_name'].'">'; }
                            else { echo '<li class="switch-lang" original-title="'.$l['native_name'].'">'; }
                        if(!$l['active']) echo '<a href="'.$l['url'].'">';
                            if($l['code'] != 'zh-hant') { echo substr($l['native_name'], 0, 2); } else { echo $l['native_name']; }
                        if(!$l['active']) echo '</a>';
                        echo '</li>';
                    }
                echo '</ul></div>';
            }
        }
    }
}
Patrick
  • 5,526
  • 14
  • 64
  • 101
Jaimee Page
  • 21
  • 1
  • 7
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – mmm Feb 07 '18 at 15:10
  • 1
    Already looked through all of that. not relevant to this question. worked absolutely fine before theme updated so no code has been touched. – Jaimee Page Feb 07 '18 at 15:16

1 Answers1

0

According to Polylang's documentation, the orderby parameter only accepts slug, name or id as valid values. In the code above, you're passing code.

Try changing:

$languages = icl_get_languages('skip_missing=0&orderby=code');

to:

$languages = icl_get_languages('skip_missing=0&orderby=slug');

And:

if($l['code'] != 'zh-hant') { echo substr($l['native_name'], 0, 2); } else { echo $l['native_name']; }

to:

if($l['slug'] != 'zh-hant') { echo substr($l['native_name'], 0, 2); } else { echo $l['native_name']; }
cabrerahector
  • 3,653
  • 4
  • 16
  • 27