Here we are going to show you how to add a column of features image in Custom Post Type Grid in back end
Here is corresponding code to the workaround we created a custom post type with the slug team so hooks become like
The following hooks pattern is used
add_filter('manage_{post type slug}_posts_columns', 'callback_function_to_add_column');
add_action('manage_{post type slug}_posts_custom_column', 'callback_function_for_data', 10, 2);
The following is complete code workaround
add_filter('manage_cookie-drops_posts_columns', 'cookie_drops_custom_column');
function cookie_drops_custom_column($defaults) {
$defaults['featured_image'] = 'Featured Image';
$defaults['cookie_status'] = 'Cookie Status';
$defaults['cookie_qty'] = 'Cookie Qty';
return $defaults;
}
add_filter('manage_cookie-drops_posts_custom_column', 'cookie_drops_custom_column_data',10, 2);
function cookie_drops_custom_column_data($column_name, $post_ID){
if ($column_name == 'featured_image') {
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
$src = wp_get_attachment_image_src($post_thumbnail_id, 'featured_preview');
if ($src) {
echo '
';
}
}
if ($column_name == 'cookie_status') {
echo get_post_meta ( $post_ID, 'cookie_status', true );
}
if ($column_name == 'cookie_qty') {
echo get_post_meta ( $post_ID, 'stock_quantity', true );
}
}
![Add Featured Image to Posts Grid/Column in Back-end for Custom Post Types [CPT] 2 screen19](https://i0.wp.com/unbeatenwebsolutions.com/wp-content/uploads/2024/07/screen19.jpg?resize=640%2C349&ssl=1)