I am using woocommerce and i have around 1500 product in one category, i have a brand as a custom taxonomy, and on category page i grab all brands based on product id, Here when i pass post_per_page to -1 it shows out of memory issue,
I have increased memory limit to 500M as well but still same.Here is the code
global $post; global $product; $cate = get_queried_object(); $catename = $cate->slug; $category_id = $cate->id; $taxonomy = 'product_cat'; $args = array( 'post_type' => 'product', 'posts_per_page' =>-1, 'product_cat' => $catename, 'orderby' => 'ASC','hide_empty'=> 1 ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $termbrand = wp_get_post_terms($loop->post->ID,'brand')->term_id; endwhile;
it works when i write like, so it can not process more post and take long time.
$args = array( 'post_type' => 'product', 'posts_per_page' =>1200, 'product_cat' => $catename, 'orderby' => 'ASC','hide_empty'=> 1 );