WordPress query_posts() orderby => ‘title’ not working

I’m having a problem ordering some posts in a navigation list on a wordpress site. here is my (badly indented) code:

<ul class="tree lvl-0">
        <?php
            $args = array('child_of' => 6);
            $categories = get_categories( $args );
            foreach($categories as $category) {
                echo '<li class="collapsed"><a href="' . get_category_link( $category->term_id ) . '"' . $category->name  . '" ' . '>' . $category->name.'</a>';
                $cat_id= $category->term_id;
                wp_reset_query();
                $args = array(
                    'cat' => $cat_id,
                    'posts_per_page' => 20,
                    'order' => 'ASC',
                    'orderby' => 'title'
                );
                query_posts($args);
                            // start the wordpress loop!
                        ?>
                            <ul class="lvl-1">
                                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                        <li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
                                <?php endwhile; endif; ?>
                            </ul>
                        </li>
            <?php wp_reset_query(); } ?>
    </ul>

the part in question is the

Read More
$args = array(
    'cat' => $cat_id,
    'posts_per_page' => 20,
    'order' => 'ASC',
    'orderby' => 'title'
);
query_posts($args);

Im not too sure what order they are in, It might be date.
Also, when I order by ‘name’ or anything else, it works. 🙁

Thanks for any help in advance

Related posts

Leave a Reply

2 comments

  1. Problem is $args, do this:

    $args = array(
        'cat' => $cat_id,
        'posts_per_page' => 20,
        'orderby' => array( 'title' => 'ASC' )
    );
    

    You can also order by multiple parameters, like:

    $args = array(
        'cat' => $cat_id,
        'posts_per_page' => 20,
        'orderby' => array( 'menu_order' => 'ASC', 'title' => 'ASC', 'post_date' => 'DESC' ),
    );