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 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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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 );
share|improve this answer
add comment

Your Answer

 
discard

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

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