Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

wp_get_attachment_metadata() not working on host (but is offline)

Hi,

I'm trying to display the date a photo was taken. I got it working, but when I pushed it online, it no longer worked. I suspect that the way the site is hosted is restricting access to the metadata. Is this possible?

Here's how I'm calling it:

<?php $photo = get_field('photo');?> <?php $image_meta = wp_get_attachment_metadata($photo["id"]);?> <?php $image_time = $image_meta[image_meta][created_timestamp];?> <?php var_dump($image_time);?>

It returns null (string(1) "0"), despite the image having metadata and working on a local server.

I would appreciate any tips/ideas/helps.

Thanks, Matthew

1 Answer

rydavim
rydavim
18,814 Points

I don't have much WP experience, but I can try to help you trouble shoot. Are you getting and errors? If so, please post them here.

You could try using wp_read_image_metadata instead and see if that works.

For trouble shooting, I would start by making sure it's got the photo. If you try to return $photo, does it come back as you expect? If so, can you access the meta data generally? If so, can you access other meta data elements? You'll want to start by figuring out where the code on the server is running into issues.

If you've got specific errors, or a live demo I might be able to give you some more specific advice.