Posted By

tomdowning on 09/21/11


Tagged

wordpress


Versions (?)

WP custom admin columns


 / Published in: PHP
 

display custom columns within admin area

  1. //DISPLAY CUSTOM POST COLUMNS
  2. add_filter('manage_collections_posts_columns', 'manage_collections_columns');
  3. add_action('manage_collections_posts_custom_column', 'print_collections_column', 10, 2);
  4.  
  5. function manage_collections_columns($existing_columns) {
  6. $existing_columns['_columnname'] = 'Column Name';
  7. return $existing_columns;
  8. }
  9.  
  10. function print_collections_column($column_name, $post_id) {
  11. if( $column_name == '_columnname' ) {
  12. //do something
  13. }
  14. }
  15.  
  16.  
  17. //SORT BY CUSTOM POST COLUMNS
  18. add_action( 'parse_request', 'mytest_parse_request' );
  19. function mytest_parse_request( $wp ) {
  20. global $wp_query;
  21. $wp_query->is_main_loop = true;
  22. return $wp;
  23. }
  24.  
  25. if ( is_admin() ) add_filter('pre_get_posts', 'filter_by_issues');
  26. function filter_by_issues($query) {
  27. global $wp_query;
  28. $posttype = $query->get('post_type');
  29. if($posttype == 'post' && isset($query->is_main_loop) && $query->is_main_loop) {
  30. $value = $_GET['meta_value'];
  31. $query->set('meta_key', 'meta_value' );
  32. $query->set('meta_value', $value );
  33. }
  34.  
  35. return $query;
  36. }

Report this snippet  

You need to login to post a comment.