Home › Forums › General Issues › Function to Return Image Caption from ID not Image Object? › Reply To: Function to Return Image Caption from ID not Image Object?
Im getting nowhere on this. So frustrating
Is caption even part of the array from wp_get_attachment_metadata?
Because I cant get it to return it, and a var dump doesnt seem to show it:
array(5) {
["width"]=>
int(400)
["height"]=>
int(300)
["file"]=>
string(19) "2018/07/400x300.png"
["sizes"]=>
array(3) {
["thumbnail"]=>
array(4) {
["file"]=>
string(19) "400x300-150x150.png"
["width"]=>
int(150)
["height"]=>
int(150)
["mime-type"]=>
string(9) "image/png"
}
["medium"]=>
array(4) {
["file"]=>
string(19) "400x300-300x225.png"
["width"]=>
int(300)
["height"]=>
int(225)
["mime-type"]=>
string(9) "image/png"
}
["square"]=>
array(4) {
["file"]=>
string(19) "400x300-300x300.png"
["width"]=>
int(300)
["height"]=>
int(300)
["mime-type"]=>
string(9) "image/png"
}
}
["image_meta"]=>
array(12) {
["aperture"]=>
string(1) "0"
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
string(1) "0"
["copyright"]=>
string(0) ""
["focal_length"]=>
string(1) "0"
["iso"]=>
string(1) "0"
["shutter_speed"]=>
string(1) "0"
["title"]=>
string(0) ""
["orientation"]=>
string(1) "0"
["keywords"]=>
array(0) {
}
}
}
Here is the code I tried:
<?php
$id = get_field('primary_image');
$img_meta = wp_get_attachment_metadata( $id );
echo $img_meta[image_meta][caption];
?>
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.