WordPress.org

Support

Support » How-To and Troubleshooting » Sorting By 'menu_order' in admin screen on non-hierarchical custom post types

Sorting By 'menu_order' in admin screen on non-hierarchical custom post types

  • Is it possible to sort by ‘menu_order’ in the admin display screen on non-hierarchical custom post types?

    I’m trying to do something like this, but it only works for hierarchical post types.

    function set_custom_post_types_admin_order($wp_query) {
      if (is_admin()) {
        // Get the post type from the query
        $post_type = $wp_query->query['post_type'];
        // if it's one of our custom ones
        if ( $post_type == 'my_custom_post_type') {
          $wp_query->set('orderby', 'menu_order');
          $wp_query->set('order', 'ASC');
        }
      }
    }
    add_filter('pre_get_posts', 'set_custom_post_types_admin_order');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Sorting By 'menu_order' in admin screen on non-hierarchical custom post types’ is closed to new replies.
Skip to toolbar