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
- Complex Slider Shortcode Help
- Using _e() on text inside video tags prints that text, instead of only showing when html5 element is not supported
- Youtube shortcode
- Shortcode will not pass attribute through to my function [duplicate]
- Displaying audio player as preview in audio post in WP3.6
- Checking for ‘gallery’ shortcode using strpos always returns false
- How to transform WordPress user role code to WP shortcode?
- Native gallery custom html output
- Does short-code slow down my WordPress site?
- redirect if shortcode exists
- Position shortcode off [duplicate]
- ob_get_clean(); doesn’t return $value in shortcode?
- How to Get Shortcode in Excerpt to follow Document Flow
- Content between shortcodes
- Parsing a shortcode through an author meta textfield
- Adding YouTube button to TinyMCE editor
- How to find out what handler is registered to a shortcode
- tiny_mce_before_init preventing custom shortcode icon appearing
- Custom Fields – Boolean Display of True/False to Yes/No
- Twitter bootstrap tabs
- jQuery Tabs in Shortcode API
- how to stop a gallery slideshow
- Echo Extra Shortcode HTML to wp_foot
- How can I use a plugin shortcode inside of a html form?
- Pre-load images into a new users media gallery
- Disable wpautop on Shortcode attributes
- remove shortcode pagination for specific url referrer
- Shortcode PHP file for two conditions passed when do shortcode
- Using within a shortcode
- Add audio file to post using custom term meta field as link [closed]
- Display tags cloud from a specific category ID with a shortcode
- How to list child pages with excerpts, e.g. [child-pages depth=”1″ excerpt=”1″]
- Video shortcode outside WordPress not working with IE and mediaelement’s Flash fallback
- Inserting a variable into a shortcode inside php
- Display title of child pages in shortcode
- How to use extract shortcode in loop?
- Clarify: Enqueueing scripts within shortcode only loads in footer?
- Create plugin/function to catch XML-data via Shortcode
- Why My slider shortcode display above header
- Shortcode conversion to hrml when post is published
- Shotcode error on functions
- Shortcode for displaying the user’s first name?
- php codes ruins shortcode structure
- Getting the wrong featured image on archive page
- $m in pre_do_shortcode_tag