Add sortable column to WordPress admin


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. add_filter( 'manage_posts_columns', 'namespace_AddXXXColumn' );
  2. add_action( 'manage_posts_custom_column', 'namespace_AddXXXValue', 10, 2 );
  3.  
  4. function namespace_AddXXXColumn($cols) {
  5. $cols['xxx'] = __('XXX');
  6. return $cols;
  7. }
  8. function namespace_AddXXXValue($column_name, $post_id) {
  9. if ( 'xxx' == $column_name ) {
  10. echo get_permalink($post_id); // for example
  11. }
  12. }
  13. // Register the column as sortable
  14. function xxx_column_register_sortable( $columns ) {
  15. $columns['xxx'] = 'xxx';
  16.  
  17. return $columns;
  18. }
  19. add_filter( 'manage_edit-post_sortable_columns', 'xxx_column_register_sortable' );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.