We have a custom post type slugged 'download' and it acts like a posts but with the different slug. (It displays content like a post). Now, We have a custom field named "videos" and different videos are uploaded and attached in each posts of 'download'.

The video fields returns with an array https://prnt.sc/Hh9WtkKm8ZZa (This is ACF Gallery but we managed to display and attached videos in gallery field but we need to keep it array).

We wanted to get the file size of the videos uploaded in each post and display it in each post after post title of the downloads. (Single Post Page).

For example:

*VIDEO1 * 68MB
*VIDEO2 * 100MB
*VIDEO3 * 200MB

The video attributes are saved and displays backend in the media page but we wanted to show it frontend after the video player. https://prnt.sc/Qf5M-V3rNHAp

To summarize, we wanted to get the all the video file size that is attached in the post. We also plan to sum all the attached video file for user doesn't need to view it 1 by 1.

//This is the code for the loop we are using to display videos. 
//This works properly displaying video so dont mind the full size because we have also an image inside the loop. 

 if (!empty($custom_field_value)) {
                                    $media_ids = explode(',', $custom_field_value);
                                    foreach ($media_ids as $media_id) {
                                        if (wp_attachment_is_image($media_id)) {
                                            $image_display_size = $field_details['image_size'];
                                            $display_image_url = $media_thumbnail_url = wp_get_attachment_image_src($media_id, $image_display_size);
                                            $media_url = wp_get_attachment_image_src($media_id, 'full');
                                        } else {
                                            $media_url = wp_get_attachment_url($media_id);
                                        if (wp_attachment_is_image($media_id)) {

1 Answer 1


From your array, you should get the Media ID of the videos. If you have the media ID, it will be as listed below:

// Let's say you have the media ID
$meta = filesize( get_attached_file( $attachment_id ) );

By using the size format function you can list the size

echo size_format($meta);

Update according to your updated case scenario:

$custom_field_value = '8785,8786,8787'; //If your custom field contains the IDs like this, simply replace my text with the custom field
if (!empty($custom_field_value)) {
    $media_ids = explode(',', $custom_field_value);
    if ($media_ids) {
        echo '<ul>';
        foreach ($media_ids as $media_id) {

            $file_size = size_format(filesize( get_attached_file( $media_id ) ));
            echo '<li>'.get_the_title($media_id).' - '.$file_size.'</li>';
        echo '</ul>';


enter image description here

  • We tried this inside the single post calling the attachment and inside the loop but still no luck. (Edited the question for the loop code) Commented Mar 28, 2023 at 17:17
  • Hi! Thank you for the answer but it doesn't really work for me. Maybe the problem is the videos are already offloaded? But the video file information are still written in the media page. Commented Mar 30, 2023 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.