Skip to content

Instantly share code, notes, and snippets.

@guillaumevoisin
Created August 27, 2012 08:42
Show Gist options
  • Save guillaumevoisin/3486719 to your computer and use it in GitHub Desktop.
Save guillaumevoisin/3486719 to your computer and use it in GitHub Desktop.
WordPress: Get post attachments
// place inside loop
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo apply_filters('the_title', $attachment->post_title);
the_attachment_link($attachment->ID, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment