The posts_column_register_sortable
function, hooked onto posts_column_register_sortable
returns an array with names of sortable columns as keys and their corresponding value what to sort by (e.g. ‘post_title’ etc).
In your case you’ve given it ‘post_views’ to sort by, which doesn’t exist as a column – so you need to tell WordPress how to sort by it. Which you kind of do in the posts_column_orderby
function, hooked onto request
. However the variable the orderby
variable you check is 'post_views_count'
, not the ‘post_views’ you set above. Change one of them to match the other and it should work.