1

In the cpanel error log WordPress generates this error:

PHP Warning: Invalid argument supplied for foreach () in /home/padtvro/public_html/wp-content/themes/claudia/content.php on line 30

If I delete it, it appears again in 6-7 hours. What's the problem?

<section id="contents" class="clearfix"><div class="row main_content"><div class="container content_wraper"><?php the_breadcrumb(); ?><div class="grid_8" id="content"><div class="widget_container content_page"><?php require_once dirname(__FILE__) . '/include/cat.php'; ?> 
</div></div><div class="grid_4 p7ehc-a" id="sidebar">
<?php $ge_sidebar = '';
                 if (is_search()) {
                      $ge_sidebar = of_get_option('se_sidebar','');
                    }else if(is_category() ) {

                        $category = get_the_category();                     

                        $cn_sidebar ='';
                        foreach($category as $ca_id) {
                            if(empty($cn_sidebar)) { $cn_sidebar = of_get_option('cat_'.$ca_id->term_id);}                              

                        }

                        if(empty($cn_sidebar)) {
                            $ge_sidebar = of_get_option('cat_sidebar','');
                        } else { $ge_sidebar = $cn_sidebar; }


                    } else if(is_author() ) {

                        $ge_sidebar = of_get_option('au_sidebar','');

                    }else if(is_tag() ) {

                        $tags = get_the_tags();                     

                        $cn_sidebar ='';
                        foreach($tags as $tg_id) {
                            if(empty($cn_sidebar)) { $cn_sidebar = of_get_option('tag_'.$tg_id->term_id);}                              
                        }

                        if(empty($cn_sidebar)) {
                            $ge_sidebar = of_get_option('tag_sidebar','');
                        } else { $ge_sidebar = $cn_sidebar; }
                    }               



                $dyn_sidebar ='';
                if(!empty($ge_sidebar)) {   $dyn_sidebar = $ge_sidebar; };              

                foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) {
                    if($sidebar['name'] == $dyn_sidebar)
                        {
                             $dyn_sidebar = $sidebar['id'];
                        }
                } 

                if(!empty($dyn_sidebar)) {
                    if (is_active_sidebar($dyn_sidebar)) : dynamic_sidebar($dyn_sidebar);
                    endif;  
                } else{
                    if (is_active_sidebar('center-sidebar')) : dynamic_sidebar('center-sidebar');
                    endif;
                }

    ?></div><div class="clear"></div></div></div></section>

1
  • 2
    Is this from a theme you developed, or one you bought/downloaded. If it's from another developer you need to raise the issue with them so that they can resolve the issue in a way that will be safe from updates. Commented Mar 31, 2020 at 13:10

1 Answer 1

1

The error is generated by this code:

line 27 $tags = get_the_tags();                     
line 28
line 29                    $cn_sidebar ='';
line 30                    foreach($tags as $tg_id) {

If a post has no tags, get_the_tags() wil return false. Then supplying false to the foreach statement will get you the error mentioned. In order to prevent this you should wrap the foreach in if (!empty($tags)) { foreach ...}.

4
  • Wedding where and how to change, Can't edit that code?
    – Pop Daniel
    Commented Apr 1, 2020 at 15:36
  • And the solution which is please? Because the person who made my site died of Covid!
    – Pop Daniel
    Commented Apr 1, 2020 at 15:58
  • The solution is in the last line of the answer.
    – cjbj
    Commented Apr 1, 2020 at 19:06
  • Edit the code directly, put it where you need it, so we don't make any extra mistakes. THX
    – Pop Daniel
    Commented Apr 2, 2020 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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