WordPress.org

Ready to get started?Download WordPress

Forums

Sorting By 'menu_order' in admin screen on non-hierarchical custom post types (2 posts)

  1. brainbrian
    Member
    Posted 2 years ago #

    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');
  2. Captain Theme
    Member
    Posted 1 year ago #

    This works perfectly for me for a non-hierarchical post type!
    PS. Thanks for that code :)

Topic Closed

This topic has been closed to new replies.

About this Topic