Woocommerce - 致命错误:允许的内存大小为134217728字节耗尽错误

时间:2017-08-08 08:33:30

标签: wordpress woocommerce

我在woocommerce工作,我创建了品牌和类别。对于我在woocommerce中创建自定义分类的品牌。当管理员输入产品时,他将选择品牌,然后选择产品类别。在前端,我在品牌页面上显示所有品牌,当用户点击任何品牌,然后显示该品牌的所有类别。首先,该品牌将获取该产品的所有产品和类别。这是我获取品牌类别的代码。此代码工作正常,但有超过50,000个产品,现在它显示内存相关的错误。我是否需要更改查询,因为我在wordpress和php.ini中增加了php内存限制。

致命错误:允许的内存大小为134217728字节耗尽(尝试分配20480字节)

$subCatArr = get_related_cat_taxo($taxonomy='brands', $term_id, $relatedCat='product_cat' ); 
            $rows = ceil(count($subCatArr) / 3); 
            $rowsConst = $rows;
            $rows = 0; // for first div.
            $first = true; 
            foreach($subCatArr as $key=>$value): 

                $term = get_term_by('id', $value, 'product_cat', 'ARRAY_A');
                $child_term = get_term( $value, 'product_cat' );
                $parent_term = get_term( $child_term->parent, 'product_cat' );
                if($parent_term)
                {
                    $catUrl =  site_url()."/product-category/".$brandSlug.'/'.$parent_term->slug.'/'.$term['slug'];
                }else{
                    $catUrl =  site_url()."/product-category/".$brandSlug.$term['slug']; 
                }   
                if ($rows == 0): 
                    $rows = $rowsConst;
                    if (!$first) {
                        echo "</ul>\n";
                    } else {
                        $first = false;
                    }   

                echo '<ul class="alphabeticall_list_5col">';
                ?>
                <?php //echo get_category_link( $value ); ?>
                <li> <a href="<?php echo $catUrl; ?>"><?php echo get_cat_name( $value ); ?></a></li>
                <? else: ?> 
                <li> <a href="<?php echo $catUrl; ?>"><?php echo get_cat_name( $value ) ?></a></li>
            <?php 
            endif;
            $rows--;
            endforeach;
        ?> 

    this is function in function.php file

    function get_related_cat_taxo($taxonomy, $term_id, $relatedCat) { 

        $args = array( 
               'post_type' => 'product', 
               'post_status' =>'publish', 
               //'posts_per_page'   => -1,
               'tax_query' => array( 
                'relation' => 'AND',  
                   array( 
                      'taxonomy' => $taxonomy, 
                      'field' => 'id', 
                      'terms' => array($term_id), 
                      'include_children' => false, 
                      'operator' => 'IN' 
                   ), 
                ) 
            );
            $loop = new WP_Query( $args );
            $subCatArr = array();
            //if( $loop->have_posts() ) : 
            while ( $loop->have_posts() ) : $loop->the_post(); 
            global $product; 
            //now get the another category of the product..
            $post_id = get_the_ID();
            //get the category of this particular product 
            $term_list = wp_get_post_terms($post_id, $relatedCat, array('fields'=>'ids','order'=>'DESC',));
            foreach( $term_list as $value ){
                if( array_search( $value, $subCatArr, true ) === false ){  
                    array_push( $subCatArr, $value );
                }
            }
            endwhile; 
            wp_reset_postdata();   
            if (($key = array_search($term_id, $subCatArr)) !== false) { 
                array_splice($subCatArr, $key, 1);
            }

            return $subCatArr;
    }

0 个答案:

没有答案