wordpress - How does one grab an attachment ID of file types that are not images? -
i've found terrific number of tutorials/code examples provide code grab , echo attachment id of image, not single 1 works else, such zip , rar archives - precisely i've working with.
would know how go grabbing , echoing id of file (in case, zip archive) within wordpress attachment.php
page? oddly enough, grabbing id of zip archive appears simple when attempted via single.php
, i'm struggling nail within attachment.php
.
really can't understand why wordpress has built-in get_post_thumbnail_id();
images, nothing available other type of file.
refer example show attachments current post beside thumb on (ironically, given comments!) get_post_thumbnail_id()
codex page.
basically set get_posts()
query all attachments. you'd need filter results on file type extension, or if know (and it's recorded correctly), wp_post.post_mime_type
using get_post_mime_type()
.
(the example filters out featured image/thumb too... filter take care of anyhow).
but if can use mime type filter, can set get_posts()
args 'post_mime_types'
argument, return attachments of 1 (or more) specific mime type(s). you'd want take peek @ attachments' underlying database entries check how recorded can match against it. expect .zip files application/zip
, i'd double check before relying on that.
so, like:
<?php $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->id, 'post_mime_type' => 'application/zip' ); $attachments = get_posts( $args ); ?>
Comments
Post a Comment