R
R
Roman2015-03-20 16:02:29
PHP
Roman, 2015-03-20 16:02:29

How to display a sortable column with post IDs in the WordPress admin?

Good afternoon.
I'm trying to display a sortable column with post IDs in the wordpress admin.
/* Adding a column with IDs of posts and pages to the admin */ Source

function true_id($args){
  $args['post_page_id'] = 'ID';
  return $args;}
function true_custom($column, $id){
  if($column === 'post_page_id'){
    echo $id;   }}
add_filter('manage_pages_columns', 'true_id');
add_action('manage_pages_custom_column', 'true_custom',10, 2);
add_filter('manage_posts_columns', 'true_id');
add_action('manage_posts_custom_column', 'true_custom',10, 2);

ID are displayed - everything is ok.
/* add the ability to sort the column */ Source
add_filter('manage_edit-post_sortable_columns', 'add_views_sortable_column');
function add_views_sortable_column($sortable_columns){
  $sortable_columns['post_page_id'] = 'views_views';
  return $sortable_columns;}

It becomes possible to sort by the ID column, when pressed, the line looks like:
/wp-admin/edit.php?orderby=views_views&order=desc
But in fact, sorting occurs not by the "ID" field, but by the "Date" field.
What could be the problem?
Thank you for your reply.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2015-03-20
@llgruff

$sortable_columns['post_page_id'] = 'ID';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question