Using the post ID
-
Hello,
I am looking to add the image caption text to the attachment page on my site. At present I get only the image description.I found the following function in a post on the www.remarpro.com site:
function wp_get_attachment( $attachment_id ) { $attachment = get_post( $attachment_id ); return array( 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'href' => get_permalink( $attachment->ID ), 'src' => $attachment->guid, 'title' => $attachment->post_title ); }
Call the function with:
$attachment_meta = wp_get_attachment(your_attachment_id);
Then put the text on the webpage with:
echo $attachment_meta['caption'];
Beginner that I am I understand most of what is here except this, how/where do I get the ID number?
When I look at the function call I assume that the “attachment” is not the page I am building but the image I am putting on the page. Since the image appears on the page OK the ID was used, right? Where do I get it to include in the $attachment_meta call?
ps
If you go to the URL included with this question just click on an image to go to the attachment page for the image.The page I need help with: [log in to see the link]
- The topic ‘Using the post ID’ is closed to new replies.