Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question