# Manual Ordering for Custom Post Types

> Adds the Order field to chosen post types and sorts them by it on the front end and in the admin, so you can control the order of team members, services or FAQs.

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

## Code

```php
// Post types ordered by their Order field.
$wpide_ordered_types = array( 'team', 'service', 'faq' );

add_action( 'init', function () use ( $wpide_ordered_types ) {
    foreach ( $wpide_ordered_types as $type ) {
        if ( post_type_exists( $type ) ) {
            add_post_type_support( $type, 'page-attributes' );
        }
    }
}, 99 );

add_action( 'pre_get_posts', function ( $query ) use ( $wpide_ordered_types ) {
    if ( ! $query->is_main_query() || $query->get( 'orderby' ) ) {
        return;
    }

    $type = $query->get( 'post_type' );

    if ( ( is_admin() && is_string( $type ) && in_array( $type, $wpide_ordered_types, true ) ) || ( ! is_admin() && $query->is_post_type_archive( $wpide_ordered_types ) ) ) {
        $query->set( 'orderby', array( 'menu_order' => 'ASC', 'title' => 'ASC' ) );
    }
} );
```

## Notes

Set the order under Page Attributes (or "Order" in the block editor's sidebar). Items with the same number sort by title.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Manual Ordering for Custom Post Types" 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/
