hi,
i also was looking for a way to attach a file to multiple posts and posts types. and for me also it wasn’t possible to retrieve these files in the posts where the library was saying the file was attached to… so i ended up to create a function that seems to work ?? here it is :
<?php
/*
Plugin Name: File Un-Attach Helper Functions
Plugin URI: https://www.xparkmedia.com
Description: This function must be used to retrieve attachments added to multiple posts by File Un-Attach.
Author: Sébastien Méric
Version: 0.1
Author URI: https://www.sebastien-meric.com
Requires at least: 3.1.0
Tested up to: 3.2
Copyright 2010-2011 by Sébastien Méric https://www.sebastien-meric.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not,write to the Free Software
Foundation,Inc.,51 Franklin St,Fifth Floor,Boston,MA 02110-1301 USA
*/
// Stop direct access of the file
if(preg_match('#'.basename(__FILE__).'#',$_SERVER['PHP_SELF'])) die();
function fun_get_attachments( $args = array() ) {
global $post;
$defaults = array(
'post_parent' => 0,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
'numberposts' => -1,
'meta_key' => '',
'meta_value' => '',
);
$args = wp_parse_args( $args, $defaults );
if ( !$args['post_parent'] )
$args['post_parent'] = $post->ID;
if ( !$args['post_parent'] )
return array();
// usual way to get pdf attached to this post
$attachments = get_children( $args );
// FileUnattach way to get attachments
if ( !$attachments && class_exists( 'FileUnattach' ) ) {
$args['post_parent'] = '';
$args['meta_key'] = '_fun-parent';
$args['meta_value'] = $post_parent;
$attachments = get_posts( $args );
}
if ( !$attachments ) {
return array();
}
return $attachments;
}
?>
make a plugin/file-unattach-helper/file-unattach-helper.php file with this content the use something like this to get pdf attachments for exemple :
$attachments = fun_get_attachments( array( 'post_mime_type' => 'application/pdf' ) );
i hope this could help.
Séb.