Custom post type: Add “Edit | Quick Edit | Trash | View” links to date (if title is not shown in column)?

This is not easily done as there is no hook to add the rows actions. You can however, unregister the date column and re-register your own date column with the row actions added. A bit hacky unfortunately.

I have tried to ensure that the following code is for post type ‘testimonials’

First register your new date column and unregister the old: (use manage_{post_type}_posts_columns hook)

add_filter('manage_testimonials_posts_columns', 'my_custom_date_column_head'); 
function my_custom_date_column_head($columns) {  
    $columns['date2'] = 'Date';  
    unset( $columns['date'] );
    return $columns;  
}

Then make your new date column sortable, (by ‘date’). Use manage_edit-{post_type}_sortable_columns hook)

add_filter( 'manage_edit-testimonials_sortable_columns', 'my_custom_date_column_sort' );
function my_custom_date_column_sort( $columns ) {
    $columns['date2'] = 'date';
    return $columns;
}

Now comes the fun bit – displaying the content of the column. I have pretty much copied and pasted what WordPress does to fill the date column and then added the actions onto the end.

Use manage_{post_type}_posts_custom_columns hook)

add_action( "manage_testimonials_posts_custom_column", 'my_custom_date_column_content',10,2);
function my_custom_date_column_content($column, $post_id ){
    global $post,$mode;

    if( 'date2' != $column )
        return;

    //**** Display default content of date column *******//

    if ( '0000-00-00 00:00:00' == $post->post_date ) {
        $t_time = $h_time = __( 'Unpublished' );
        $time_diff = 0;
    } else {
        $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
        $m_time = $post->post_date;
        $time = get_post_time( 'G', true, $post );

        $time_diff = time() - $time;

        if ( $time_diff > 0 && $time_diff < 24*60*60 )
            $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
        else
            $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
    }

    if ( 'excerpt' == $mode )
        echo apply_filters( 'post_date_column_time', $t_time, $post, $column, $mode );
    else
        echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column, $mode ) . '</abbr>';

    echo '<br />';

    if ( 'publish' == $post->post_status ) {
        _e( 'Published' );

    } elseif ( 'future' == $post->post_status ) {
        if ( $time_diff > 0 )
            echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
        else
        _e( 'Scheduled' );

    } else {
        _e( 'Last Modified' );
    }

    //***** END  -- Display default content of date column *******//


    //***** START  -- Our actions  *******//

    //First set up some variables
    $actions = array();
    $post_type_object = get_post_type_object( $post->post_type );
    $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );


    //Actions to edit
    if ( $can_edit_post && 'trash' != $post->post_status ) {
        $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
        $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
    }

    //Actions to delete/trash
    if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
        if ( 'trash' == $post->post_status )
            $actions['untrash'] = "<a title="" . esc_attr( __( "Restore this item from the Trash' ) ) . "' href="" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . "&amp;action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";

        elseif ( EMPTY_TRASH_DAYS )
            $actions['trash'] = "<a class="submitdelete" title="" . esc_attr( __( "Move this item to the Trash' ) ) . "' href="" . get_delete_post_link( $post->ID ) . "">" . __( 'Trash' ) . "</a>";

        if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
            $actions['delete'] = "<a class="submitdelete" title="" . esc_attr( __( "Delete this item permanently' ) ) . "' href="" . get_delete_post_link( $post->ID, "', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
    }

    //Actions to view/preview
        if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
            if ( $can_edit_post )
                $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';

        } elseif ( 'trash' != $post->post_status ) {
                $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
        }

    //***** END  -- Our actions  *******//

    //Echo the 'actions' HTML, let WP_List_Table do the hard work
    echo WP_List_Table::row_actions( $actions );
}

Leave a Comment