# Sort a Post Type Archive A to Z

> Lists the items of chosen post type archives in alphabetical order by title instead of newest first, for directories, glossaries and catalogs.

- Type: PHP
- Runs: Run everywhere
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: archives, ordering, custom-post-types
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/alphabetical-post-type-archive/

## Code

```php
// Post type archives sorted by title.
$wpide_az_types = array( 'glossary_term', 'location', 'partner' );

add_action( 'pre_get_posts', function ( $query ) use ( $wpide_az_types ) {
    if ( ! is_admin() && $query->is_main_query() && $query->is_post_type_archive( $wpide_az_types ) && ! $query->get( 'orderby' ) ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );
    }
} );
```

## Notes

Their taxonomy archives keep the default order.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Sort a Post Type Archive A to Z" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
