2

I have picked through Scribu's post very carefully and cannot determine where the issue is.

Here is the code:

// Register the column
function event_date_column_register( $columns ) {
$columns['event-date'] = __( 'Event Date', 'my-plugin' );

return $columns;
}
add_filter( 'manage_edit-event_columns', 'event_date_column_register' );

// Display the column content
function event_date_column_display( $column_name, $post_id ) {
if ( 'event-date' != $column_name )
    return;

$event_date = get_post_meta($post_id, 'event-date', true);
if ( !$event_date )
    $event_date = '<em>' . __( 'undefined', 'my-plugin' ) . '</em>';

echo $event_date;
}
add_action( 'manage_event_custom_column', 'event_date_column_display', 10, 2 );

// Register the column as sortable
function event_date_column_register_sortable( $columns ) {
$columns['event-date'] = 'event-date';

return $columns;
}
add_filter( 'manage_edit-event_sortable_columns', 'event_date_column_register_sortable' );


function event_date_column_orderby( $vars ) {
if ( isset( $vars['orderby'] ) && 'event-date' == $vars['orderby'] ) {
    $vars = array_merge( $vars, array(
        'meta_key' => 'event-date',
        'orderby' => 'meta_value',
        'order'     => 'asc'
    ) );
}

return $vars;
}
add_filter( 'request', 'event_date_column_orderby' );

I have a custom post type for Event with a custom field: event-date dates are entered: 2011/06/21

Is this something stupid I have missed or this won't do what I want? It does put the heading up at the top of the admin events list but nothing shows in each line item.

1 Answer 1

4

i believe the right hook for displaying the actual column content (each line) is

manage_{$post_type}_posts_custom_column

so change in your code:

add_action( 'manage_event_custom_column', 'event_date_column_display', 10, 2 );

to:

add_action( 'manage_event_posts_custom_column', 'event_date_column_display', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.