No Need for SQL queries in the template.
function wpse_72594_get_attachments( $id, $mime="" )
{
$args = array(
'post_type' => 'attachment',
'post_mime_type' => $mime,
'post_parent' => $id
);
$attachments = get_posts($args);
if ($attachments)
return $attachments;
return false;
}
Then call the function like this (300 is the post ID):
wpse_72594_get_attachments(300)
, grabs all attachmentswpse_72594_get_attachments(300, 'image' )
, only imageswpse_72594_get_attachments(300, 'application/pdf' )
, only pdf files
Related Posts:
- conditional shortcode not working
- conditional shortcode not working
- Add custom setting that uses radio button to WP Gallery
- Check if post/page has gallery?
- how to have the gallery shortcode output one single UL list instead of several DL?
- Automatically add this attribute to the gallery shortcode
- Video embeds work in backend, but are not parsed in frontend
- Hide Default Video Shortcode Controls on PageLoad
- WordPress core responsive video not working with shortcode
- How do i link gallery thumbnails to different url’s using the wp native gallery?
- WordPress gallery ‘post_gallery’ filter doesn’t work with feeds?
- Remove width and height attributes from [gallery] output
- Gallery shortcode menu order fix no longer working on WordPress 4.0
- Some doubts about gallery shortcode in WordPress
- Should I cache default WordPress gallery shortcode output?
- Audio and video shortcodes not working properly
- Numbering Image List in Gallery
- Conditionally loading Facebook PHP SDK in shortcode
- Rewriting WordPress Gallery Shortcode with Bootstrap Carousel
- change wordpress gallery shortcode to slider
- Remove hyperlink on gallery shortcode
- WordPress Gallery shortcode: Display one category ID only
- How to get gallery id inserted to a post?
- How to Modify WordPress Default Image Gallery Shortcode
- Change WordPress Shortcode added in to post
- conditional tags- how to use with shortcodes
- Gallery shortcode – change link file image size? (not using default fullsize image)
- add action only if gallery shortcode attribute is equal to?
- How To Conditionally Include A Short Code Depending On The HTTP_REFERER [closed]
- Ho to add “Create Slider” option to default “Add Media” popup?
- Unable to the get the gallery inserted between shortcodes
- Adding shortcode field to edit gallery / Gallery Settings
- How to change the output of gallery shortcode
- Gallery shortcode numerical sorting
- Replacement for gallery_shortcode function not taking all attributes
- Check if CTP category taxonomy is set in shortcode
- How to Retrieve data of Gallery Shortcode and display it above a post
- How to copy [gallery] shortcode between posts using polylang [closed]
- Which file renders the “Edit Gallery” Settings page?
- How to display NextGEN gallery in templates?
- Use full size images in a specific gallery
- hard code shortcode only on specific category
- How to Enable embedding WordPress default gallery in comments?
- How to add new images to existing shortcode configuration?
- Gallery shortcode is empty but magically creates a gallery
- Can we add a single caption to the gallery shortcode?
- Automatically add class-attribute to gallery?
- Replace custom gallery shortcode with default gallery shortcode
- WordPress Gallery with ID’s Shortcode not Working
- Remove width and height attributes from [gallery] output
- Changing layout of defaul gallery output to masonry
- What makes a placeholder resizable in Tinymce?
- is_mobile as shortcode
- how to show last 5 images from the one post gallery
- Gallery Shortcode: using size=”full” doesn’t call the actual thumbnail image size
- WordPress Gallery only allowed 10 times per post
- convert it into short code & explan how? [closed]
- Enqueue Scripts / Styles when shortcode is present
- Conditionally Loading JavaScript/CSS for Shortcodes
- What does extract( shortcode_atts( array( do?
- Split Content and Gallery
- How do I escape a ‘]’ in a short code?
- Pass boolean value in shortcode
- Show shortcode without executing it
- Shortcode always displaying at the top of the page
- How to customise the output of the WP image gallery shortcode from a plugin?
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Redirect function inside a Shortcode
- How to create a shortcode with 1 parameter (atts)
- ZIP up all images displayed in a [gallery] and offer as download link
- how to show the syntax of a shortcode
- Custom shortcode being executed when saving page in wp-admin
- Change appearance of shortcode text inside editor
- current_shortcode() – detect currently used shortcode
- shortcodes output before content [duplicate]
- WordPress plugin shortcode not working
- How to add stylesheets only to pages with specific shortcode?
- Using get_option() in JavaScript
- Shortcode empty attribute
- How does a shortcode work?
- Shortcode outputs at the top of the_content
- the_excerpt and shortcodes
- Using wp_editor in shortcode
- Remove wpautop from shortcode content / remove whitespace in buffering
- Get current post id witout passing in shortcode
- Why are you using add_action for shortcode?
- How to get URL param to shortcode?
- How to add multiple buttons to TinyMCE?
- How to have different captions for same image, for galleries?
- Use a separate custom table (not posts) to handle file upload data
- Get first video from the post (both embed and video shortcodes)
- Get shortcode name from within it’s callback function? [duplicate]
- Wordspress add into my javascripts
- How to paginate wordpress [gallery] shortcode?
- Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
- How do I create a Shortcode that returns text if domain is .com, not .co.uk
- Using preg_replace to separate gallery from the_content?
- Remove specific shortcode from get_the_content()
- How to display the site name in a WordPress page, or post
- Hide/show content starting in the middle of a paragraph