Documentation > Developers > Filter Examples > Add Selection Column to the Collection Overview

Add Selection 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_status_admin_column( $columns ) {
	$new_columns['selection'] = _x( 'Selection', 'column header', '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_status_admin_column', 11 );


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

	$post_status = get_post_status( $post_id );

	if ( $column == 'selection' ) {
		if ( $post_status == 'delivery-draft' OR $post_status == 'delivered' ) {
			echo '-';
		}
		else {
			$total_images = get_post_meta( $post_id, '_picu_collection_gallery_ids', true );
			$selected = picu_get_selection_count( $post_id );
			echo $selected . ' / ';
			echo ( ! empty( $total_images ) ) ? count( explode( ',', $total_images ) ) : '0';
		}
	}

	return $column;
}


add_action( 'manage_picu_collection_posts_custom_column' , 'my_picu_column_collection_status', 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.