自定义post_per_page在Wordpress和Woocommerce中不能工作

时间:2022-10-25 10:10:33

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

我有一个网上商店,在商店页面上显示所有的产品。

I use the following code in functions.php:

我在函数中使用了以下代码。

//EDIT POSTS PER PAGE IN SHOP

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.

但当我在分类页面时,限制似乎设置为100,它显示分页。我不知道它来自哪里(在设置/阅读中它被设置为200),也不知道如何改变它。

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.

奇怪的是,如果我在category页面中使用AJAX过滤器,当我返回显示all时,它将显示没有分页的所有产品,但在页面重载时,它将显示分页。

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

关于如何显示所有产品以及如何直接在页面加载中删除分页有什么建议吗?

1 个解决方案

#1


2  

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');

#1


2  

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');