0

I have a fancy custom column on the posts page in the WordPress admin. I have this column set up to be sortable. The first time that you click on the column header, the URL in the address bar changes to order=asc and then each time that you click on it, it toggles back and forth between asc and desc. However, I'd like the first click to make it desc and then begin toggling it. How can I do that.

Here is my current code:

add_filter( 'manage_edit-post_sortable_columns', array( $this, 'my_function' ) );
public function my_function( $columns ) {
    $columns['my_column'] = 'My Column Name';
    return $columns;
}

So how do I make it so that when the column is first clicked, it goes to DESC first and then ASC? Thanks.

1

You just need to provide an array with two items — the column slug and the initial sorting order.

$columns['my_column'] = array( 'my-column', 'desc' );
| improve this answer | |
  • 1
    That did the trick, my friend. Thank you so much! Perfect. – Nicholas Cardot Aug 22 at 15:12

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.