0

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?

1 Answer 1

5

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');
    }
}
1
  • 2
    @MichaelEcklund It's Stephen, what do you expect? :-)
    – its_me
    Commented Jun 28, 2012 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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