0

Is this because of Wordpress, PHP, or the Theme? (or some combination)

A client of mine has a Wordpress site that's been working just fine for years, but recently started getting the following errors pulling up in it's sidebars:

Warning: Invalid argument supplied for foreach() in /wp-content/themes/epsilon/page-threecolumn.php on line 29

Been thinking it may have to do with upgrades to both Wordpress and PHP. Theme is no longer supported. Here is what the code looks like in that area:

                <div class="col-234">
                    <div class="sidebar left-sidebar">
                            <?php
                            $leftsidebar = simple_fields_get_post_group_values($post->ID, "Left Sidebar", false, 2);
                            foreach ($leftsidebar as $value) { 
                            ?>
                            <aside>
                                <h2> <?php echo $value[1]; ?></h2>
                                <div>
                                <?php
                                    if($value[2]):
                                        if (function_exists('cforms_insert')){ 
                                            echo cforms_insert(do_shortcode($value[2])); 
                                        } else { 
                                            echo do_shortcode($value[2]); 
                                        } 
                                    endif;
                                ?>
                                </div>
                            </aside>
                            <?php } ?>
                    </div>
                </div>

I did not build the site. And while I am proficient in pure HTML, I know little about PHP. Is this just a syntax issue that can be resolved with some quick fixes? Or do I need to go out and install a completely new theme (which scares the heck out of me)?

  • it seems that the warning is caused by the plugin wordpress.org/plugins/simple-fields (which is no longer supported/available). check if this pliugin is still active in your site... – Michael Dec 27 '19 at 3:29
  • wrap that foreach loop in if( is_array( $leftsidebar ) ){ foreach( ... ){ ... } }. This will prevent that warning being generated. – maverick Dec 27 '19 at 10:46
  • Thanks, guys. I'm afraid just getting rid of the warning isn't acceptable, but thank you. I'll look into the plugin, Michael, and I'll learn a little more php so I understand what you're saying, Maverick. For the time being I've gone with a different approach. Went to the Wayback Machine to see what it looked like before the glitch. Then I just replaced the php in that section of that file with the actual HTML that the function was failing to obtain. Not so elegant, perhaps, but hey...it works! – Daddio Dec 28 '19 at 7:53
  • Ah well, my temporary "solution" wasn't as great as I thought. Meaning we're back to the code. Michael, if I deactivate the Simple Fields plugin, I get critical warnings as opposed to just warnings. Would that be expected since the php is still trying to invoke it? – Daddio Dec 28 '19 at 23:28
0

simple_fields_get_post_group_values might be returning null or false.

Try adding:

$leftsidebar = simple_fields_get_post_group_values($post->ID, "Left Sidebar", false, 2);
echo "<!--".print_r($leftsidebar)."-->";

And check the source of the page to see what's returning.

  • Okay, I modified the PHP as you showed, no change in a web browser, source shows the error, like so: <div class="col-234"> <div class="sidebar left-sidebar"> <!--1--><br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/cd1a110/public_html/wp-content/themes/epsilon/page-threecolumn.php</b> on line <b>30</b><br /> </div> </div> – Daddio Dec 27 '19 at 1:28
0

Since Simple Fields has been removed from the plugin directory you should consider recreating the custom fields using Advanced Custom Fields (ACF) or similar and then modifying the template to use the new fields. Keep the field names the same when you register them and it should be a pretty simple fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.