Question

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.

Was it helpful?

Solution

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' );
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top