1

My products are sort by menu_order, but I would like to sort category name too. I tried a few plugins and all doesn't works.

Code, which display category name and products list:

<?php $custom_terms = get_terms('product-cat');
foreach($custom_terms as $custom_term) {
    wp_reset_query();
    $args = array(
    'post_type' => 'product',
    'posts_per_page' => 9999, 
    'orderby' => 'menu_order', 
    'order' => 'ASC',
    'tax_query' => array(
        array(
            'taxonomy' => 'product-cat',
            'field' => 'slug',
            'terms' => $custom_term->slug
        ),
    ),
    );

    $loop = new WP_Query($args);
    if($loop->have_posts()) {
        echo '<li><h3>'.$custom_term->name.'</h3>';
        echo '<ul>';
        while($loop->have_posts()) : $loop->the_post();
            echo '<li><a href="'.get_permalink().'" title="' . get_the_title() .'">'.get_the_title().'</a></li>';
        endwhile;
        echo '</ul>';
        echo '</li>';
    } 
} ?>

Thanks for reply.

Regards.

1
  • Hook a callback to posts_clauses and posts_request and see what you get in there (the SQL query). That's a good starting point as I have no idea how to add another orderby that works by cat name. Take a look at this answer as a starting point. The other ones on that question might help you as well.
    – kaiser
    Commented Feb 28, 2014 at 8:51

0

Browse other questions tagged or ask your own question.