Support » Plugins » Hacks » Sortable columns. How to set default order on menu bar?

  • Resolved phloo

    (@phloo)


    Following situation:
    – Custom Post Type created
    – Made it sortable

    Now, when opening the post list (edit.php?post-type=my_type) I want to change the order value in the sortable columns. By default it is set to “asc”. See example.

    Is it possible to change the init sort order for those links?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    It appears so. Use the filter ‘manage_edit-post_sortable_columns’ (note the hyphen in edit-post). The passed array of sortable columns is typically just the column_id/column_key as the key/value pair. This is the default for ASC order.

    The column_key value (referring to the main column definition array) can also be an array containing the column_key and false, which makes DESC the default. The default array looks like this:

    array(
      'title'    => 'title',
      'parent'   => 'parent',
      'comments' => 'comment_count',
      'date'     => array( 'date', true ),
    )

    See how the date column is formatted? It defaults to DESC. The rest default to ASC. Just format columns you want to default to DESC the same way.

    Untested, but I’m pretty confident this will work.

    Perfect, it works!

    Thanks a lot. Wish I found that somewhere in the documentation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sortable columns. How to set default order on menu bar?’ is closed to new replies.