0

The number of woocommerce product libraries and the number of default shop pages Can't match

All my products display more than 350 products, but only 270 products are displayed on the shop page, and no solution has been found so far

I have tried to use the hook function to reset the sorting and display all the exhibits, but it seems to have no effect. Using sql to query the products also shows 270

$args = array(
    'post_type'      => 'product',
    'post_status'    => 'publish',
    'posts_per_page' => -1, // all product
);

$products = new WP_Query( $args );
$i=0;
if ( $products->have_posts() ) {
    while ( $products->have_posts() ) {
        $products->the_post();

     $i++;
  
    }   
    echo 'Product—sum:'.$i;
}


function show_all_products_on_shop_page($query) {
    if (is_admin() || ! $query->is_main_query()) {
        return;
    }

    if (is_shop()) {
        $query->set('posts_per_page', -1);
    }
}
add_action('pre_get_posts', 'show_all_products_on_shop_page');

Using the above two methods does not seem to work:

enter image description here

enter image description here

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
kevin
  • 1
  • 1

1 Answers1

0

I have solved the current problem, the product release type is hidden

type hidden image

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
kevin
  • 1
  • 1