0

In my Admin Panel I have a custom post type of posts - with page attributes to define order. Is there "easy" way of changing how the admin panel pulls posts so I can reorder them?

Page Attributes define order and parents. My Custom Post Type isn't a page but it still supports Page Attributes because I want to order them in a meaningful way.

Currently in Wordpress Admin Panel when using Custom Post Types and Page Attributes, the Admin Panel doesn't order posts in the defined order, it instead orders all posts by publish date (so newest on top). I'm looking to use Page Attributes to order my Custom Post Type posts in the admin panel in the same order defined by Page Attributes.

Even more clarification:

Defined in register_post_type() as supports => array() Found Here

Shows where to find Page Attributes when inside Edit CPT

The expected outcome would be something like this, where the post with page attribute 0 is at the top and the greatest page attribute would be at the bottom:

Shows an example of the expected output with the Order set.

  • Can you elaborate on "define order" and "reorder"? – brasofilo Nov 20 '13 at 2:38
  • Well right now the posts are showing up top to bottom by latest created. I want to change the order so that they're ordered by the page attribute "Order" I defined. so that 0 will be at the top and 999 will be at the bottom. – Howdy_McGee Nov 20 '13 at 14:42
  • What is a "page attribute"? What is your custom post type? You're not giving enough information for somebody to give you a meaningful answer, much less code to do it. – Otto Dec 5 '13 at 19:38
  • Page Attributes define order and parents. My Custom Post Type isn't a page but it still supports Page Attributes because I want to order them in a meaningful way. – Howdy_McGee Dec 5 '13 at 19:43
  • Making your custom post type hierarchical allows for this sorting natively. You'll have to do a pre_get_posts to change this for your list table. – Eric Holmes Dec 5 '13 at 20:00
7
+100

Post list in admin (edit.php) use a normal WP_Query, just like frontend can be changed using pre_get_posts.

add_action('pre_get_posts', 'reorder_my_cpt');

function reorder_my_cpt( $q ) {
  $s = get_current_screen();
  // change 'book' with your real CPT name
  if ( is_admin() && $s->base === 'edit' && $s->post_type === 'book' && $q->is_main_query() ) {
    $q->set('orderby', 'menu_order');
    $q->set('order', 'ASC');
  }
}
  • This looks promising, im going to run it through a few cases! Thanks! – Howdy_McGee Dec 5 '13 at 20:07
  • You're welcome. And glad it works. – gmazzap Dec 5 '13 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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