Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created a custom post type which now has around 100 posts in it. I simply want to display these in alphabetical order by the post title rather than the default which seems to be most recent first. I've tried various plugins and other solutions, but most only allow manual sorting (too many posts for that to work), I'm told that the code below should work but it seems to have no effect at all.

Any help appreciated.

<?php 
    $args = array( 'post_type' => 'tenant', 'posts_per_page', 'orderby=title&order=ASC' => 5 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
?>
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

try this:

<?php 
$args = array( 'post_type' => 'tenant', 'posts_per_page'=>5, 'orderby'=>'title','order'=>'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>

You will find more info o custom queries here: http://codex.wordpress.org/Class_Reference/WP_Query

share|improve this answer
    
Nice solution. Makes the hour I just spent reading docs seem like a waste of time :) –  Patrik Alienus Aug 4 '13 at 22:08
add comment

I realize this is an old thread, but I came across it trying to do the same thing and settled on adding a pre-query action using functions.php rather than a template and the loop.

In my case; I have a page of about 25 yoga classes, set up as a custom post type 'classes'

// function and action to order classes alphabetically

function alpha_order_classes( $query ) {
    if ( $query->is_post_type_archive('classes') && $query->is_main_query() ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );
    }
}

add_action( 'pre_get_posts', 'alpha_order_classes' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.