This is the custom dashboard display the list of speakers as presented in WordCamp Seattle 2014. It focuses on the speaker program developed for the Bellevue Breakfast Rotary Club. Other posts in this series are:
WordCamp Seattle 2014 Custom Prev and Next Post Filters
WordCamp Seattle 2014 Speaker Program Custom Grid and Advanced Search

Speaker Program Dashboard

This is the code to create dashboard for the Speaker Program demo for my WordCamp Seattle presentation.

First, notice that all of the “manage” filters and actions include the specific custom post name, in this case, “rotary_speakers”.

manage_${post_type}_posts_columns allows the addition and removal of dashboard columns for the specific post type.

manage_${post_type}_posts_column retrieves the data for a specific column. For example, the data for the speaker’s first or last name

manage_edit-${post_type}_sortable_columns sets which columns are sortable. Here, the speaker date, speaker’s first name and speaker’s last name can be sorted.

Filtering the request is tricky as you don’t want to impact other areas of the dashboard. Be sure to check for your custom post type and/or order by variable. I have seen reference to using pre_get_posts for this instead of the request filter but have not yet tried that out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 add_filter('manage_rotary_speakers_posts_columns' , 'rotary_speakers_cpt_columns'); 
    function rotary_speakers_cpt_columns($columns) {
	    unset($columns['date']);
	    unset($columns['author']);
	    unset($columns['title']);
	    $new_columns = array(
		'speaker_date' => __('Speaker Date', 'rotary'),
		'title' => __('Title', 'rotary'),
		'speaker_first_name' => __('Speaker First Name', 'rotary'),
		'speaker_last_name' => __('Speaker Last Name', 'rotary'),
		'speaker_company' =>  __('Organization', 'rotary'),
		);
    	$columns = array_merge($columns, $new_columns);
 
	    return $columns;
    }
    add_action( 'manage_rotary_speakers_posts_custom_column' , 'rotary_custom_speaker_column_data', 10, 2 );
    function rotary_custom_speaker_column_data($column, $post_id) {
    	switch ( $column ) {
    		case 'speaker_date' :
            	$speakerDate = get_post_meta( $post_id , 'speaker_date' , true );  
            	echo date('l M dS, Y', strtotime($speakerDate));
				break;
			case 'speaker_first_name':
				echo get_post_meta( $post_id , 'speaker_first_name' , true ); 
				break;
			case 'speaker_last_name':
				echo get_post_meta( $post_id , 'speaker_last_name' , true ); 
				break;
			case 'speaker_company':
				echo get_post_meta( $post_id , 'speaker_company' , true ); 
				break;	
 
		}
 
    }
    add_filter('manage_edit-rotary_speakers_sortable_columns', 'rotary_column_register_sortable');
    function rotary_column_register_sortable( $columns )
	{
		$columns['speaker_date'] = 'speaker_date';
		$columns['speaker_first_name'] = 'speaker_first_name';
		$columns['speaker_last_name'] = 'speaker_last_name';
		return $columns;
	}
	add_filter( 'request', 'rotary_speaker_column_orderby' );
	function rotary_speaker_column_orderby( $vars ) {
    if ( isset( $vars['orderby'] ) && 'speaker_date' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
            'meta_key' => 'speaker_date',
            'orderby' => 'meta_value'
        ) );
    }
	if ( isset( $vars['orderby'] ) && 'speaker_first_name' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
            'meta_key' => 'speaker_first_name',
            'orderby' => 'meta_value'
        ) );
    }
    if ( isset( $vars['orderby'] ) && 'speaker_last_name' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
            'meta_key' => 'speaker_last_name',
            'orderby' => 'meta_value'
        ) );
    }
 
    return $vars;
}