S
S
sasha7612020-11-16 15:07:53
Twig
sasha761, 2020-11-16 15:07:53

Why doesn't sorting work on the shop page in woocommerce?

Good afternoon.
I use Timber + twig for development and I came across the fact that on the shop page I display all the products as they should and with pagination (I do this through new Timber\PostQuery($args)), but for some reason requests to the url by type / ?orderby=menu_order or /?orderby=price don't work, but when I output via get_posts() , it works

Here is the code

global $paged;
    if (!isset($paged) || !$paged){
        $paged = 1;
    }
    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 15,
        'numberposts'   => 15,
        'paged' => $paged,
    );
    $posts = new Timber\PostQuery($args);
    $context['products'] = $posts;

    // $posts = Timber::get_posts();
    // $context['products'] = $posts;

    if ( is_product_category() || is_shop() || is_tax() ) {
        $queried_object = get_queried_object();
        $term_id = $queried_object->term_id;
        $context['category'] = get_term( $term_id, 'product_cat' );
        $context['tags'] = get_term( $term_id, 'product_tag' );
        $context['title'] = single_term_title( '', false );
    }

    $context['sidebar'] = get_field( 'sidebar' );

    $context['auto_sidebar'] = [
        'tags' => get_terms(['taxonomy' => 'product_tag', 'hide_empty' => false]),
        'categories' => get_terms(['taxonomy' => 'product_cat', 'hierarchical' => false, 'parent' => 0]),
        'other' => get_categories(['type' => 'product', 'taxonomy' => 'product_cat'])
    ];

    Timber::render( 'templates/woo/archive.twig', $context );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-11-16
@wppanda5

I see no reason to use Timber,
but if it works directly and not through it, then turn on the debug and see what it asks for and how it asks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question