SHOW:
|
|
- or go back to the newest paste.
| 1 | // add custom columns | |
| 2 | add_filter('manage_ii-movies_posts_columns' , 'ii_add_movies_columns');
| |
| 3 | // add corresponding values | |
| 4 | add_action( 'manage_ii-movies_posts_custom_column', 'ii_add_movies_values', 10, 2 ); | |
| 5 | // make them sortable | |
| 6 | add_filter('manage_ii-movies_sortable_columns','ii_make_sortable_columns');
| |
| 7 | // This function deals with managing all movies | |
| 8 | function ii_add_movies_columns() {
| |
| 9 | return array( | |
| 10 | 'cb' => '<input type="checkbox" />', | |
| 11 | 'title' => __('Title'),
| |
| 12 | 'year' => __('Year'),
| |
| 13 | 'directors' => __('Director(s)'),
| |
| 14 | 'genres' =>__( 'Genres'), | |
| 15 | 'date'=>__('Date of publication')
| |
| 16 | ); | |
| 17 | } | |
| 18 | function ii_add_movies_values( $column, $post_id ) {
| |
| 19 | global $post; | |
| 20 | if ($column == 'directors') {
| |
| 21 | // Get the meta | |
| 22 | $director = get_post_meta( $post_id, 'director', true ); | |
| 23 | if ( empty( $director ) ) { echo __( 'not set' ); }
| |
| 24 | else {
| |
| 25 | for ($i=0;$i<count($director);$i++) {
| |
| 26 | $directors[]=$director[$i]['name']; | |
| 27 | } | |
| 28 | echo implode(' / ',$directors);
| |
| 29 | } | |
| 30 | } | |
| 31 | elseif ($column == 'year') {
| |
| 32 | // Get the meta | |
| 33 | $year = get_post_meta( $post_id, 'year', true ); | |
| 34 | if ( empty( $year ) ) { echo __( 'not set' ); }
| |
| 35 | else { echo $year; }
| |
| 36 | } | |
| 37 | elseif ($column == 'genres') {
| |
| 38 | // Get the meta | |
| 39 | $genres = get_post_meta( $post_id, 'genres', true ); | |
| 40 | if ( empty( $genres ) ) { echo __( 'not set' ); }
| |
| 41 | else {
| |
| 42 | echo implode(' / ',$genres);
| |
| 43 | } | |
| 44 | } | |
| 45 | } | |
| 46 | function ii_make_sortable_columns($columns){
| |
| 47 | - | // function is never called |
| 47 | + | $columns['date'] = 'date'; |
| 48 | - | unset($columns['date']); |
| 48 | + | |
| 49 | } |