Skip to content

Admin Columns

Carlos Moreira edited this page Jun 2, 2020 · 2 revisions

The admin_cols feature allows you to add custom table columns for the administration list of your custom post type entries.

This feature is entirely based on the same feature offered by the Extended CPTs library. Props to them for developing this very useful library.

You can refer to their documentation to check the available options.

Example of the admin_cols feature being used in your model:

return [
	'active'       => true,
	'type'         => 'cpt',
	'name'         => 'book',
	'features'     => [
		'admin_cols'    => [
			'featured_image' => [
				'title'          => 'Image',
				'featured_image' => 'thumbnail',
			],
			'title',
			'genre'          => [
				'taxonomy' => 'genre',
			],
			'writer'         => [
				'taxonomy' => 'writer',
			],
			'author'         => [
				'title'      => 'Entry Author',
				'post_field' => 'post_author',
			],
			'id'             => [
				'title'      => 'ID',
				'post_field' => 'ID',
			],
			'shortcode'      => [
				'title'    => __( 'Shortcode', 'framework-demo' ),
				'function' => function() {
					global $post;
					echo esc_html( '[display-book id="' . $post->ID . '"]' );
				},
			],
		],
	],
];