Answer the question
In order to leave comments, you need to log in
WooCommerce sorting not working?
On the main page, I display products only with a promotion, adding the following code:
<?php
if ( is_shop() && !is_search() ) {
$products_on_sale = wc_get_product_ids_on_sale();
$args = array(
'post_type' => 'product',
'post__in' => array_merge(array(0), $products_on_sale)
);
query_posts( $args );
}
?>
<?php if ( have_posts() ) : ?>
query_posts( $args );
Answer the question
In order to leave comments, you need to log in
The documentation suggests to form an array before passing the
WP_Query parameter
// This will NOT work
$exclude_ids = '1,2,3';
$query = new WP_Query( array( 'post__not_in' => array( $exclude_ids ) ) );
// This WILL work
$exclude_ids = array( 1, 2, 3 );
$query = new WP_Query( array( 'post__not_in' => $exclude_ids ) );
Apparently, the loop does not work because the function is_shop()
checks whether the given page is a shop page or not. Most likely you have another page (not the main one) in your settings.
and another moment of aesthetics)) you don’t need to merge arrays in the post__in attribute. Make it simple 'post__in' => array( $products_on_sale )
You can also just use a shortcode
[sale_products per_page="12" columns="4" orderby="title" order="asc"]
The problem lies in the mistranslation, or I would say misunderstanding of the meaning of the words. In fact, sorting works correctly, given that the code says low to high, which means “from low to high”, but in translation into Russian we see the words “descending”, so sorting by price does not work correctly.
wavifun.ru/ne-rabotaet-sortirovka-po-zene-woocommerce
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question