Product display limited to 9 by category in custom archives-shop
-
Hi all!
I display all my products on one page but I only realized recently that the display is limited to 9 items per category; if I go to the category’s page though, it displays everything, example with the spices and herbs category:
https://www.lockoloop.nl/#cat-29
https://www.lockoloop.nl/product-category/spices-herbs/ (shows all 10)
Same happens with any category that has more than 9 items.I’m guessing something in my code (I didn’t write it) is responsible for this because I tried with another theme and the same happens (I removed what’s not part of the loop).
The only lead I have is that the Products by category widget also displays 9 products by default (3×3), maybe this code is missing some kind of settings?<?php // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } if ( is_admin() ) return false; // Gets products per category // first we need to get the product categories .... $categories_args = array( 'taxonomy' => 'product_cat' // the taxonomy we want to get terms of ); $product_categories = get_terms( $categories_args ); // get all terms of the product category taxonomy if ( is_admin() ) return false; echo '<ul class="woocommerce">'; // now we are looping over each term foreach ($product_categories as $product_category) { $term_id = $product_category->term_id; // Term ID $term_name = $product_category->name; // Term name $term_desc = $product_category->description; // Term description $term_link = get_term_link($product_category->slug, $product_category->taxonomy); // Term link echo '<li class="cat-title" id="cat-'.$term_id.'">'; // for each term we will create one list element echo '<h3>'.$term_name.'</h3>'; // display term name // ... now we will get the products which have that term assigned... $products_args = array( 'post_type' => 'product', // we want to get products 'posts_per_page' => -1, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $term_id, // here we enter the ID of the current term *this is where the magic happens* ), ), ); $products = new WP_Query( $products_args ); if ( $products->have_posts() ) { // only start if we hace some products // START some normal woocommerce loop, as you already posted in your question woocommerce_product_loop_start(); while ( $products->have_posts() ) : $products->the_post(); wc_get_template_part( 'content', 'product' ); endwhile; // end of the loop. woocommerce_product_loop_end(); // END the normal woocommerce loop // Restore original post data, maybe not needed here (in a plugin it might be necessary) wp_reset_postdata(); } else { // if we have no products, show the default woocommerce no-product loop // no posts found do_action('woocommerce_no_products_found'); }//END if $products echo '</li>';//END here is the end of our product-cat-term_id list item }//END foreach $product_categories echo '</ul>';//END of catalog list
Any idea?
Thank you.As a side note, this code also prevents the search function to work normally since it returns either none or all products.
- The topic ‘Product display limited to 9 by category in custom archives-shop’ is closed to new replies.