• Hi,
    I got stuck at this problem, I need to make a custom menu of portfolio-items, that goes Portfolio -> categories -> items from the category. Unfortunately, it shows all the portfolio-items instead of just from the category.
    Thanks for your help
    The site: https://www.brightthemes.8u.cz

    <?php
    if ( !function_exists( 'brighttheme_portfolio_filtering' ) ) {
            function brighttheme_portfolio_filtering() {
    
                $brighttheme_portfolio_filtering_html = '
    
                        <li id="menu-item" class="menu-item"><a href="#"> <span>'. esc_html__('PORTFOLIO','brighttheme') .'</span> </a> 
    
                          ';
                            foreach ( get_terms('category') as $category ){
                                $brighttheme_portfolio_filtering_html .= '<li id="menu-item" class="menu-item"><a href="#" data-filter=".'
                                                                        .'">'. ( $category->name )
                                                                        .'<ul class="sub-menu">';
                            $args = array('post_type' => 'portfolio',
                                'category' => $category, );
    
                           $portfolios = get_pages($args); 
    
                            foreach ( $portfolios as $portfolio_item ){
                                $brighttheme_portfolio_filtering_html .= '<li id="menu-item" class="menu-item"><a>ID ) .'" data-filter=".';
                                $brighttheme_portfolio_filtering_html .= get_page_link( $portfolio_item ->ID ) .'">'. $portfolio_item ->post_title;
                                $brighttheme_portfolio_filtering_html .= '</a>';
                            }
                            $brighttheme_portfolio_filtering_html .= '
                             ';
                            }
                          $brighttheme_portfolio_filtering_html .= '
                       ';
                echo $brighttheme_portfolio_filtering_html;
            }
        }
    ?>
  • The topic ‘foreach in foreach’ is closed to new replies.