Eric Mitjans Eric Mitjans - 4 years ago 94
Ajax Question

Custom post_per_page not working in categories in Wordpress and Woocommerce

I have an online shop which display all products in the shop page.

I use the following code in functions.php:


add_filter( 'loop_shop_per_page', create_function( '$cols', 'return -1;' ));

When I'm in the main shop page this works without a problem.

But when I'm in a category page, the limit seems to set at 100 and it shows pagination.
I don't know where it comes from (in Settings/Reading it's set at 200), or how to change it.

Weirdly enough, if I use the AJAX filters in the category page, when I go back to displaying all, it will show all products without pagination, but on page reload it will show the pagination.

Any tips on how to display all products and get rid of the pagination directly on page load?

Answer Source

Try below code, it is removing pagination and you can apply further condition inside function too.

function no_nopaging($query) {
     if ($query->is_archive()) {
        $query->set('nopaging', 1);

add_action('parse_query', 'no_nopaging');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download