Paging parameters ignored when modifying the WooCommerce loop
-
Hello,
My client has requested a recent products category however they do not want to add the recent products to the category manually.
As such I have created “recent” under product categories and I am just trying to modify the woocommerce loop to show the 12 most recent products on the taxonomy page /product-category/recent/
My code is below however it is not working as expected.
function recent_woo_query( $query ) { if ( is_product_category('recent') ) { $query->set( 'product_cat', '' ); $query->set( 'orderby', 'date' ); $query->set( 'order', 'desc' ); $query->set( 'posts_per_page', 12 ); $query->set( 'nopaging', 'true' ); //$query->set( 'max_num_pages', 1 ); } } add_action( 'woocommerce_product_query', 'recent_woo_query' );
There are two issues:
1. I cannot remove the pagination so we only see the 12 most recent products. If I have nopaging set to true then ALL products are shown rather than the just the most recent 12 and if I have nopaging set to false and max_num_pages set to 1 then that is also ignored and the pagination shows which means a large number of pages as there are a lot of products in the store. How can I remove the pagination other than hiding it with CSS?
2. Using the code above the first page is showing 11 products, not 12 as per the subsequent pages. I can fix this on the first page by changing the number to 13 rather than 12 however then the subsequent pages which are showing up even thought I don’t want them too have 13 products. Why is the woocommerce loop showing 1 less product on the first page than the subsequent pages?
So for now I have set the posts_per_page to 13, nopaging to false and hidden the pagination using CSS to effectly show only 12 posts, however I’m not comfortable with this messy workaround.
Thanks very much for your assistance to make this work correctly.
Nicole
- The topic ‘Paging parameters ignored when modifying the WooCommerce loop’ is closed to new replies.