3 edited title
| link

How doto get posts ordered by using their categories?

2 extra tag update
| link
1
source | link

How do get posts ordered by using their categories?

I have a page where I've got all the products on a single page. -- Link to the test site.

What I'd like to do is to get the products ordered using their categories. Juices, nectars, concentrates, etc.

The usual

$orderby =

id
name 
slug
count
term_group 

doesn't get them ordered the way needed. Is it even possible and if so, how would I achieve this?

My products.php:

<?php
/*
Template Name: Products
*/
get_header();
?>
</div>

<?php
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$taxonomy = 'mahlakategooriad';
$title = '';
$args = array(
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'taxonomy' => $taxonomy,
'title_li' => $title
);
$term_obj =  get_terms($taxonomy,$args);
$type = 'produktid';
$args = array( 'post_type' => 'produktid', 'posts_per_page' => 1);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php
    echo '<div class="main small">';
    echo '<h1><a href="'.get_permalink().'">'.get_the_title().'</a></h1>';
    the_content();
    echo '</div>';
?>
<div class="big-pic"><?php echo get_the_post_thumbnail( $loop->post->ID, 'tooted-big' ); ?></div>
<?php
endwhile;
$args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1,
    'orderby' => 'date', 
    'order' => 'ASC' 
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
?>
<div class="tooted">
<?php 
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php 
    $toote_thumb = get_the_post_thumbnail( $page->ID, 'tooted-thumb' ); 
    $toote_big = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'tooted-big' );
    if ($toote_thumb) {
        echo '<div class="toode">';
        echo '<a href="'.get_permalink().'" class="toote-thumb" data-link="'.$toote_big[0].'">'.$toote_thumb.'</a>';
    }
    ?>
    <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" class="toote-title"><?php the_title(); ?></a></div>
    <?php
    endwhile;
}
wp_reset_query();
?>
<div class="clear"></div>
</div>
<div class="clear"></div>