Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add custom columns
- add_filter('manage_ii-movies_posts_columns' , 'ii_add_movies_columns');
- // add corresponding values
- add_action( 'manage_ii-movies_posts_custom_column', 'ii_add_movies_values', 10, 2 );
- // make them sortable
- add_filter('manage_ii-movies_sortable_columns','ii_make_sortable_columns');
- // This function deals with managing all movies
- function ii_add_movies_columns() {
- return array(
- 'cb' => '<input type="checkbox" />',
- 'title' => __('Title'),
- 'year' => __('Year'),
- 'directors' => __('Director(s)'),
- 'genres' =>__( 'Genres'),
- 'date'=>__('Date of publication')
- );
- }
- function ii_add_movies_values( $column, $post_id ) {
- global $post;
- if ($column == 'directors') {
- // Get the meta
- $director = get_post_meta( $post_id, 'director', true );
- if ( empty( $director ) ) { echo __( 'not set' ); }
- else {
- for ($i=0;$i<count($director);$i++) {
- $directors[]=$director[$i]['name'];
- }
- echo implode(' / ',$directors);
- }
- }
- elseif ($column == 'year') {
- // Get the meta
- $year = get_post_meta( $post_id, 'year', true );
- if ( empty( $year ) ) { echo __( 'not set' ); }
- else { echo $year; }
- }
- elseif ($column == 'genres') {
- // Get the meta
- $genres = get_post_meta( $post_id, 'genres', true );
- if ( empty( $genres ) ) { echo __( 'not set' ); }
- else {
- echo implode(' / ',$genres);
- }
- }
- }
- function ii_make_sortable_columns($columns){
- // function is never called
- unset($columns['date']);
- return $columns;
- }
Advertisement
Add Comment
Please, Sign In to add comment