当涉及到图片附件时,wordpress具有非常棒的功能 - 但我找不到任何关于如何获取不是图片附件的文档。wordpress获取不是图片的附件
现在,我写了这个功能:
function ok99_get_post_file_attachment($mime='application/pdf',$limit=-1) {
global $post;
$attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment','post_mime_type' => $mime, 'order' => 'ASC', 'orderby' => 'menu_order ID', 'posts_per_page'=>$limit));
if ($attachments) {
echo 'Your Attachments : <br/>';
foreach ($attachments as $att) {
//$attachment = array_shift($attachments); // debug to delete
echo wp_get_attachment_url($att->ID) . '<br/>';
the_attachment_link($attachment->ID, false);}
}
return false;
}
我的问题是:这是获得所有非图片附件的唯一途径? 有没有办法做到这一点,没有另一个查询?
我有点晚这个派对,所以也许你的问题已经发生了变化,但是无论如何,看到我的答案是一个一个查询的解决方案!:) – Simon 2014-02-13 13:35:05