Home Forums Front-end Issues Split: Template Code doesn't work


Split: Template Code doesn't work

  • Hi Elliot, thanks for the response! I’ve already seen these 2 pages, but I’m still having some troubl

    1. I cant create a new topic, it gives me the message: The ACF support forum is closed to new topics at this time.

    2. I’m using the FILE uploader, and, I can get file info, but. If I let the return url in OBJECT it gives me the “description” correctly, but not the “file size”. If I turn the return URL to ID it gives me the size, but the not the description…this is my code:

    <?php if( get_field(’tile_package’) ) {

    $image = wp_mime_type_icon(‘archive’);
    $attachment_id = get_field(’tile_package’);
    $url = wp_get_attachment_url( $attachment_id );
    $title = get_the_title( $attachment_id );
    $description = wp_get_attachment_metadata( $attachment_id );
    $filesize = filesize( get_attached_file( $attachment_id ) );
    $filesize = size_format($filesize, 2); // 2 é para 2 casas decimais, ficou mais legal e preciso do que 2 MB, qq coisa vc tira.

    and the ussage is:

    <?php echo $image ?>
    <?php echo $title; ?>
    <?php echo $filesize; ?>
    <?php echo $attachment_id [‘description’]; ?> *THIS ONE WORKS ONLY IF THE RETURN URL IS OBJECT*

    This is the page I’m using it:

    Thanks a million

  • Hi @caju

    New topics are only allowed to be added from Monday to Friday. In the future, please do not jump onto another thread and post your question. Instead, wait until the support forum hours are open.

    As for your question, the file field does not return the filesize data. I’ll add this to the to-do, but for now, you can load it like so:

    $attachment = get_field(’tile_package’);
    $filesize = size_format(filesize( get_attached_file( $attachment['ID'] ) ));


  • Hi @elliot

    I have the same issue, I used your solution but still i can not able to display the file size. Other than your solution i also tried this.

    $attachment_id = get_field('attach_report');
     $url = wp_get_attachment_url( $attachment_id );
     $title = get_the_title( $attachment_id );
     $filesize = $attachment_id;
     $filesize = size_format($filesize, 2);
    echo '<a href="'. get_field('attach_report') .'" download>Download PDF (' . $filesize .' ) </a>';
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Split: Template Code doesn't work’ is closed to new replies.