Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a Custom Post Type (CPT) called Sessions.

The List Table in the admin for this Custom Post Type (CPT) has the following columns:

  • Session # (post id)
  • Session (post title)
  • Day (CPT meta value)
  • Room # (CPT meta value)
  • Time Slot (CPT meta value)

I want the default ordering for the table to first sort by Day, followed by Room #, followed by Time Slot all, in ascending order.

I currently have this code in place :

add_filter( 'manage_session_posts_columns', 'session_columns' );
add_action( 'manage_posts_custom_column', 'session_column_data', 10, 2 );
add_filter( 'request', 'session_column_orderby' );

// CPT Sessions
function session_columns( $cols ) {
    $cols = array(
        'cb' => '<input type="checkbox" />',
        'session_number' => 'Session #',
        'title' => 'Session',
        'session_day' => 'Day',
        'session_room' => 'Room',
        'session_time_slot' => 'Time Slot'
    return $cols;

// CPT column data
function session_column_data( $column, $post_id ) {
    switch ( $column ) {
        case 'session_day':
            echo get_post_meta( $post_id, 'session_day', true);
        case 'session_room':
            echo get_post_meta( $post_id, 'session_room', true);
        case 'session_time_slot':
            echo get_post_meta( $post_id, 'session_time_slot', true);

function session_column_orderby( $vars ) {
    if (  isset( $_GET['post_type'] ) && ( $_GET['post_type'] == 'cpt_session'  )) {
        $vars['orderby'] = 'session_day';
        $vars['order'] = 'asc';
        $vars = array_merge( $vars, array(
            'meta_key' => 'session_day',
            'orderby' => 'meta_value'
    return $vars;

That last function will set the default sorting to sort the table by the CPT meta_value 'session_day' (I do not want the default sorting to be by post title).

How do I change this to sort by the these three meta_values (in order of importance) 'session_day', 'session_room', 'session_time_slot' ?

share|improve this question
This might help. –  toscho Jun 24 '13 at 1:02
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.