CyberShot Posted February 10, 2018 Share Posted February 10, 2018 (edited) I am working in WordPress building a widget for siteorigin page builder. The widget is working just fine but I am getting an undefined index error and I don' t know why. I have a file that returns and array. That is all that it does. It looks like this but has a lot more indexes. 'facebook' => array( 'label' => __( 'Facebook', 'mosty' ), 'base_url' => 'https://www.facebook.com/', 'class' => 'fa fa-facebook', ), 'twitter' => array( 'label' => __( 'Twitter', 'mosty' ), 'base_url' => 'https://twitter.com/', 'class' => '', ), I have added the class index to the array and I am using the facebook one as my test. I need to get the result of the "class" index and send it to the front end of the site. I have that working. It does display on the front end. In the front end file, I have a bit of code to error check to see if I can get the value I brought the array file into the back end like this if( empty( $this->networks ) ) { $this->networks = include plugin_dir_path( __FILE__ ) . 'data/networks.php'; } ?php foreach ($network_names as $key => $value){ echo '<ul><li>The key is '. $key . ' The value is ' . $value . '</li></ul>'; } ?> Here is the output of my test loop and at this point, this is all I would expect and the first entry is correct The key is facebook The value is fa fa-facebook The key is twitter The value is The key is google-plus The value is The key is linkedin The value is The key is tumblr The value is The key is vk The value is The key is flickr The value is The key is delicious The value is The key is dribbble The value is The key is skype The value is The key is youtube The value is The key is github The value is The key is forrst The value is The key is digg The value is The key is soundcloud The value is On the front end of the site, I am getting this error Notice: Undefined index: class in /path to widget/team/team.php on line 111 Here is my line 111 109 $network_names = array(); 110 foreach ( $this->networks as $key => $value ) { 111 $network_names[ $key ] = $value['class']; 112 } I am sending the array to the front end of the site on line 121 of team.php I have attached my team.php class to the post for you to view. Again, the widget does work and does display the data but gives me that undefined index for "class" index of my array. How can I solve this problem? team.php Edited February 10, 2018 by CyberShot Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 11, 2018 Share Posted February 11, 2018 Have you dumped this 'value' array variable to see what it contains? That would be the start. Quote Link to comment Share on other sites More sharing options...
Solution CyberShot Posted February 11, 2018 Author Solution Share Posted February 11, 2018 Looks like the problem was that I missed adding the class index to one of the options. The error is gone Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.