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.

So I am using a custom post type to create a listing of businesses. Each post made, contains information about each business. The title of each post is the name of the business.

When I go to the menu created by the custom post type, I receive a standard listing of posts. (or in this particular case, a listing of business names). The posts show in a random order (or possibly being sorted by date on default?)

How can I allow for my posts to be listed in alphabetical ascending order by default?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You should use pre_get_posts:

add_action('pre_get_posts','wpse56753_businesses_default_order');
function wpse56753_businesses_default_order( $query ){
    if( 'business' == $query->get('post_type') ){
        if( $query->get('orderby') == '' )
            $query->set('orderby','title');

        if( $query->get('order') == '' )
            $query->set('order','ASC');
    }
}
share|improve this answer
    
Perfect. Works like a charm. Thanks. –  Michael Ecklund Jun 28 '12 at 0:31
2  
@MichaelEcklund It's Stephen, what do you expect? :-) –  its_me Jun 28 '12 at 2:38

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.