admin管理员组

文章数量:1325236

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.

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.

Share Improve this question asked Aug 22, 2020 at 14:32 Nicholas CardotNicholas Cardot 1851 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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' );

本文标签: How do I change the default sort order of a custom column on the posts page