This worked for me and I am able to get the file type extension but now I would like to use an if statement with that extension so I can assign icons to my files based on the file type. So for example, if the filetype equals pdf then I would output a pdf icon. How can I do an if else type of statement using this?
I tried the following but no luck:
<?php $attachment_id = get_field('document_upload');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
// part where to get the filesize
$filesize = filesize( get_attached_file( $attachment_id ) );
$filesize = size_format($filesize, 2);
$path_info = pathinfo( get_attached_file( $attachment_id ) );
// show custom field
if (get_field('document_upload')): ?>
<?php echo $filesize; ?>
<?php echo $path_info['extension']; ?>
<?php
if ($path_info = "pdf") {
echo "<i class='fa fa-file-pdf-o' aria-hidden='true'></i>";
} ?>
<?php endif; ?>
Not really sure where to go from here. Thanks
Figured it out. The code is fine I just had to go into the custom fields admin page and chanage the “Return Value” from image URL to image ID.
So none of those solutions worked but I did find something that did. I used the following code and was able to get the image to finally show up.
<?php
$publisher_photo = get_the_author_meta('user_profile_image');
$image_src = wp_get_attachment_image_src($publisher_photo);
echo '<img class="avatar" src="'. $image_src[0] .'" />';
?>
Thank you for your help with this.
I did have the return value for image. I also tried your code but am still only getting it to output the image ID. http://s15.postimg.org/q2ycawbwb/Capture.jpg
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.