Skip Navigation

[Resolved] Dimension column in Post Types

This thread is resolved. Here is a description of the problem and solution.

Problem:

Display the featured image Dimension as column in the post list page of wordpress dashboard.

Solution:

It needs custom codes, see the solution here:

https://toolset.com/forums/topic/dimension-column-in-post-types/#post-1145578

Relevant Documentation:

https://codex.wordpress.org/Plugin_API/Filter_Reference/manage_$post_type_posts_columns

https://codex.wordpress.org/Function_Reference/get_post_thumbnail_id

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by tK-4 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1145172

How could I add a media 'dimension' column to any Toolset - Custom Post Type - All Items screen? The code below I have added to my custom_function.php to add a dimension column to the media libary itself. However, I do not know how to edit for use in any/all Post Types. The 'dimension' data would have to pull from the Post Type itself, verses the image in the Media Libary. I use an outdated plugin (https://wordpress.org/plugins/bulk-images-to-posts/) to bulk import media directly into your Post Type. While it also places same image in Media Libary, it uses a differnt ID#.

/* START OF ADDING A DIMENSION COLUMN TO MEDIA LIBRARY */
function wh_column( $cols ) {
        $cols["dimensions"] = "Dimensions (w, h)";
        return $cols;
}
function wh_value( $column_name, $id ) {
    if ( $column_name == "dimensions" ):
    $meta = wp_get_attachment_metadata($id);
           if(isset($meta['width']))
           echo $meta['width'].' x '.$meta['height'];
    endif;
}
add_filter( 'manage_media_columns', 'wh_column' );
add_action( 'manage_media_custom_column', 'wh_value', 10, 2 );
/* END OF ADDING A DIMENSION COLUMN TO MEDIA LIBRARY */
#1145578

Hello,

I assume you are going to display the featured image Dimension as column in the post list page, if it is, you can try below PHP codes:

function my_wh_column( $cols ) {
        $cols["dimensions"] = "Dimensions (w, h)";
        return $cols;
}
function my_wh_value( $column_name, $id ) {
    if ( $column_name == "dimensions" ){
		$thumbnail_id = get_post_thumbnail_id($id);
		$meta = wp_get_attachment_metadata($thumbnail_id);
        if(isset($meta['width']))
           echo $meta['width'].' x '.$meta['height'];
	}
}
add_filter( 'manage_my-cpt_posts_columns', 'my_wh_column', 999);
add_action( 'manage_my-cpt_posts_custom_column', 'my_wh_value', 999, 2 );

Please replace "my-cpt" with your custom post type slug

More help:
https://codex.wordpress.org/Plugin_API/Filter_Reference/manage_$post_type_posts_columns
https://codex.wordpress.org/Function_Reference/get_post_thumbnail_id

#1145810

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.