can anyone help me to sort Posts list in WP-admin by wp_posts table field like comment_status.
I know, that we can easy sort by meta field key, but cannot find any way how to sort by wp_posts table actual field.
If we dig in to source code of WP Query, we can find that there are allowed only these types of keys -
$allowed_keys = array( 'name', 'author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', 'comment_count', 'type' );
Is there any way how to override them?
This is how I can sort by meta_key, but I need to sort by actual table field.
add_filter('manage_edit-post_sortable_columns', 'jepc_add_comments_column_table_sorting');
add_filter('request', 'jepc_column_sort');
function jepc_add_comments_column_table_sorting($columns) {
$columns['comment_status'] = 'comment_status';
return $columns;
}
function jepc_column_sort($vars) {
if (isset( $vars['orderby']) && 'comment_status' == $vars['orderby']) {
$vars = array_merge( $vars, array(
'meta_key' => 'comment_status',
'orderby' => 'meta_value'
));
}
return $vars;
}
Thanks.