I'm attempting to get the attached/inserted images in my Wordpress php
code that I inserted into a test post in the admin interface. I clicked the "Add Media" button and uploaded my pictures and updated the post (where front-page
is the custom post type).
(I clicked this button):
However, I can't seem to retrieve the picture associated with that post for the life of me. If I set a Feature Image
(thumbnail), I can get that, but not inserted images. Here's what I've tried:
Looping Through Attachments (No luck):
$attachments = query_posts(
array(
'post_type' => 'front-page', // only get "attachment" type posts
'post_parent' => $post->ID, // only get attachments for current post/page
'posts_per_page' => -1 // get all attachments
)
);
foreach($attachments as $attachment) {
echo get_the_ID();
echo wp_get_attachment_image( $attachment->ID, 'full' );
}
wp_attached_image(post ID) (No luck):
wp_get_attachment_image( $post->ID );
Getting all the posts (No luck):
<?php
$args = array(
'post_type' => 'front-page',
'post_mime_type' => 'image',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attached_images = get_posts( $args );
echo $attached_images[0];
?>
Getting the post gallery images (No luck)
get_post_gallery_images( $post->ID );
I'm really lost as to why I can't retrieve the images. I've exhausted nearly every suggestion I could find online, and was wondering if it had something to do with my custom post type or what? Any help would be appreciated.
I think you are missing the resulting code with echo (as I am doing below) or print or output. I managed to do it with this code a while ago.. hope it helps-(using fancybox in this one)