Documentation > Developers > Filter Examples > Add Tracking Column to The Collection Overview

Add Tracking Column to The Collection Overview

// We recommend using this snippet inside a custom plugin: https://picu.io/docs/developers/using-a-custom-plugin/

/**
 * Set column header
 */
function my_picu_collection_add_tracking_admin_column( $columns ) {
	$new_columns['tracking'] = _x( 'Tracking', 'column header', 'my-picu' );

	$offset = 3;
	$columns = array_slice( $columns, 0, $offset, true ) + $new_columns + array_slice( $columns, $offset, NULL, true );

	return $columns;
}

add_filter( 'manage_picu_collection_posts_columns', 'my_picu_collection_add_tracking_admin_column', 11 );


/**
 * Set column content
 */
function my_picu_column_content_tracking( $column, $post_id ) {

	$post_status = get_post_status( $post_id );
	$tracking_data = get_post_meta( $post_id, '_picu_delivery_download_tracking', true );
	$output = '-';

	if ( ( $post_status == 'delivery-draft' OR $post_status == 'delivered' ) && ! empty( $tracking_data ) && is_array( $tracking_data ) ) {
		$last_access = end( $tracking_data );
		$output = __( 'Last download:', 'my-picu' ) . '<br />' . wp_date( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), $last_access['time'] );
	}

	if ( $column == 'tracking' ) {
		echo $output;
	}
}


add_action( 'manage_picu_collection_posts_custom_column' , 'my_picu_column_content_tracking', 10, 2 );Code language: PHP (php)

Need help?

If you couldn’t find what you were looking for and need more assistance, please get in touch with us directly and we’re happy to help.