PHP Warning: Invalid argument supplied for foreach() on line 62? Can't figure it out
<p>I have an ajax slider in wordpress which is generating  the Invalid Argument error which seems to stem from</p>

<pre><code>&lt;li class="portfolio-col-&lt;?php echo $portfolio_column_count++; ?&gt;" data-portfolio="portfolio-&lt;?php echo $post-&gt;ID; ?&gt;" data-id="id-&lt;?php echo $idCount++; ?&gt;" data-type="&lt;?php foreach ($portfolio_cats as $taxonomy) { echo 'filter-' . $taxonomy-&gt;slug . ' '; } ?&gt;"&gt; 
</code></pre>

<p>which is line 62 form the code below. I can't figure it out so nay help would be appreciated.</p>

<pre><code>&lt;div class="ajax-portfolio-block-wrap"&gt;
    &lt;?php if (have_posts()) : ?&gt;
        &lt;?php while (have_posts()) : the_post(); ?&gt;
                &lt;?php $page_title=get_the_title(); ?&gt;

                &lt;div class="ajax-gallery-navigation"&gt;
                    &lt;div id="ajax-portfolio-loading"&gt;&lt;/div&gt;
                    &lt;a class="ajax-navigation-arrow ajax-prev" href="#"&gt;Prev&lt;/a&gt;
                    &lt;a class="ajax-navigation-arrow ajax-next" href="#"&gt;Next&lt;/a&gt;
                &lt;/div&gt;
                &lt;div class="ajax-portfolio-window"&gt;
                    &lt;div id="ajax-portfolio-wrap"&gt;&lt;/div&gt;
                &lt;/div&gt;

        &lt;?php endwhile; else: ?&gt;
    &lt;?php endif; ?&gt;

    &lt;?php
    $idCount=1;
    $columns=4;
    ?&gt;
    &lt;div class="fullpage-contents-wrap"&gt;
        &lt;div class="page-container"&gt;
            &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt;
                &lt;h2 class="ajax-projects-title"&gt;&lt;?php echo $page_title; ?&gt;&lt;/h2&gt;
                &lt;div class="portfolio-works-wrap"&gt;
                        &lt;ul class="portfolio-filter clearfix"&gt;
                        &lt;li class="current all"&gt;&lt;a href="#"&gt;&lt;?php _e('All','mthemelocal'); ?&gt;&lt;/a&gt;&lt;/li&gt;
                        &lt;?php                   
                        $categories=  get_categories('child_of='.$portfolio_cat_ID.'&amp;orderby=slug&amp;taxonomy=types&amp;title_li=');
                        foreach ($categories as $category){ ?&gt;
                        &lt;li class="&lt;?php echo "filter-" . $category-&gt;slug;?&gt;"&gt;&lt;a href="#"&gt;&lt;?php echo $category-&gt;name;?&gt;&lt;/a&gt;&lt;/li&gt;
                        &lt;?php }?&gt;
                        &lt;/ul&gt;
                &lt;/div&gt;

                &lt;div class="portfolio-filter-wrap clearfix"&gt;
                    &lt;ul class="portfolio-list"&gt;
                        &lt;?php
                        $newquery = array(
                            'post_type' =&gt; 'mtheme_portfolio',
                            'types' =&gt; $portfolio_cat_slug,
                            'orderby' =&gt; 'menu_order',
                            'order' =&gt; 'ASC',
                            'posts_per_page' =&gt; -1,
                            );
                        query_posts($newquery);
                        if (have_posts()) : while (have_posts()) : the_post();
                        $custom = get_post_custom(get_the_ID());
                        $portfolio_cats = get_the_terms( get_the_ID(), 'types' );
                        $video_url="";
                        $thumbnail="";
                        $link_url="";
                        if ( isset($custom["video"][0]) ) { $video_url=$custom["video"][0]; }
                        if ( isset($custom["thumbnail"][0]) ) { $thumbnail=$custom["thumbnail"][0]; }
                        if ( isset($custom["custom_link"][0]) ) { $link_url=$custom["custom_link"][0]; }
                        $portfolio_thumb_header=$custom["portfolio_page_header"][0];

                        if ($portfolio_column_count&gt;$columns) $portfolio_column_count=1;

                        ?&gt;
                       // ** Line 62 ** // &lt;li class="portfolio-col-&lt;?php echo $portfolio_column_count++; ?&gt;" data-portfolio="portfolio-&lt;?php echo $post-&gt;ID; ?&gt;" data-id="id-&lt;?php echo $idCount++; ?&gt;" data-type="&lt;?php foreach ($portfolio_cats as $taxonomy) { echo 'filter-' . $taxonomy-&gt;slug . ' '; } ?&gt;"&gt;
                            &lt;span class="ajax-image-selector"&gt;&lt;/span&gt;

                            &lt;?php
                            if ( $custom["video"][0]&lt;&gt;"" ) {
                                $p_class="fadethumbnail-play";
                            } elseif ( $custom["custom_link"][0]&lt;&gt;"" ) {
                                $p_class="fadethumbnail-link";
                            } else {
                                $p_class="fadethumbnail-view";
                            }
                            ?&gt;
                                &lt;?php
                                    if ($portfolio_thumb_header=="Slideshow") {
                                        echo '&lt;a class="portfolio-image-link portfolio-ajax" rel="'.$post-&gt;ID.'" ref="'.$video_url.'" &gt;';
                                        echo '&lt;span class="column-portfolio-icon portfolio-slideshow-icon"&gt;&lt;/span&gt;';
                                        } else {                            
                                            if ( $custom["video"][0]&lt;&gt;"" ) { 
                                                echo '&lt;a class="portfolio-image-link portfolio-ajax" rel="'.$post-&gt;ID.'" ref="'.$video_url.'" &gt;';
                                                echo '&lt;span class="column-portfolio-icon portfolio-video-icon"&gt;&lt;/span&gt;';
                                                } elseif ( $custom["custom_link"][0]&lt;&gt;"" ) {

                                                    echo '&lt;a class="portfolio-image-link portfolio-ajax" rel="'.$post-&gt;ID.'" ref="'.$custom["custom_link"][0].'" &gt;';
                                                    echo '&lt;span class="column-portfolio-icon portfolio-image-icon"&gt;&lt;/span&gt;';

                                                } else {
                                                echo '&lt;a class="portfolio-image-link portfolio-ajax" rel="'.$post-&gt;ID.'" ref="'.featured_image_link($post-&gt;ID).'" &gt;';
                                                echo '&lt;span class="column-portfolio-icon portfolio-image-icon"&gt;&lt;/span&gt;';
                                            }
                                    }
                                ?&gt;
                                &lt;?php
                                // Show Image
                                if ($thumbnail&lt;&gt;"") {
                                    echo '&lt;img src="'.$thumbnail.'" class="preload-image displayed-image" alt="thumbnail" /&gt;';
                                } else {
                                    echo display_post_image (
                                        $post-&gt;ID,
                                        $have_image_url=$thumbnail_image_url,
                                        $link=false,
                                        $type="portfolio-small",
                                        $post-&gt;post_title,
                                        $class="preload-image displayed-image"
                                    );
                                }
                                ?&gt;
                                &lt;span class="ajax-image-title"&gt;&lt;?php the_title(); ?&gt;&lt;/span&gt;         
                                &lt;/a&gt;
                        &lt;/li&gt;
                        &lt;?php endwhile; ?&gt;
                        &lt;?php endif;?&gt;

                    &lt;/ul&gt;
                &lt;/div&gt;
                &lt;?php
                require ( MTHEME_INCLUDES . 'clients.php' );
                ?&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
</code></pre>

<p>`</p>
