S
S
smash_wp2015-11-17 12:36:31
CMS
smash_wp, 2015-11-17 12:36:31

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() ) : ?>

It is on this main page that sorting does not work. Tried different methods. Through trials, I found out that the reason is:
query_posts( $args );
Prescribed in the 'orderby' parameters , etc. So far, nothing has helped.
Who faced such a problem, or maybe knows another way to withdraw promotional goods, tell me the solution, please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Ksenia Mikhailova, 2015-11-17
@arizona

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

M
Maxim Martirosov, 2015-11-19
@kalbac

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"]

E
E3ozKWLy0tpEkYl, 2017-04-13
@E3ozKWLy0tpEkYl

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 question

Ask a Question

731 491 924 answers to any question