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
- Conditionally Loading JavaScript/CSS for Shortcodes
- Run visual composer code in php page
- Does a shortcode with a single attribute have to use an array?
- Calling function from within functions.php returns unwanted value
- Custom field for default gallery
- Post loop created via shortcode not displaying shortcode in content
- Pass shortcode variables to template
- Is it possible to add a repeater field to TinyMCE’s option window?
- Shortcodes: Pros and Cons
- esc_attr not working in shortcode
- Raw output (preventing wpautop)
- Are .MP3 files with capital letter extensions allowed in [audio] shortcode?
- How to handle shortcodes when using the JSON API
- Are shortcode functions applied while rendering the content, or are they executed and stored with the post content?
- is_admin() returns false in save_post hook with Gutenberg editor
- Get Posts shortcode plugin and meta_query?
- possibility to control embedded video timeline with buttons and links external to the player
- Different uniqid when calld in wp_localize_script and shortcode
- Gravity forms customize field markup for the same form appearing in different places
- Check if the current shortcode is being used in a widget
- Edit shortcode in post content programatically
- How to change to local video player on shortcode ultimate to video.js?
- return unformatted content in encosing shortcode
- How to display Feedburner subscription count as plain text via a shortcode in post/page editor of my WordPress blog?
- Function result goes outside div
- Shortcode in my childtheme is not working
- Show form per shortcode
- Pass fileurl parameter into shortcode from Advanced Custom Fields
- Shortcode arguments to another shortcode
- Color on Shortcode insert that creates a button
- shortcode doesnt work on excerpt
- Adding Author URL to Nav Menu via Shortcode
- Displaying an interactive web map on my wordpress site
- Pagination for custom posts loop
- Modify [caption] shortcode so and are not used?
- WordPress show descriptions under images in gallery
- How to strip header tags & shortcodes from the_excerpt()
- shortcode display metainformation as linked image
- Reusable Dynamic Taxonomy Shortcode
- Where is escaped the shortcode?
- restrict access to specific urls on a specific period of time
- shortcode change variable base on user
- Inserting shortcode is blanking excerpt – any ideas?
- Nested ShortCode works inside the_content, but not outside of it
- How to use multiple values in “Shortcode”? [closed]