[Plugin: File Un-Attach] not sure that multiple attachments is working properly
-
I’m having an issue when trying to attach an image to multiple posts (actually of a custom post type). The interface shows “multiple” but when I view the content it only seems to be attached to the last chosen post.
There also doesn’t seem to be a way of finding out which posts it is attached to – it just says “multiple”.
Great plugin though – thanks! 🙂
-
I didn’t test this plugin with custom post types, I will test it and let you know but probably this is going to be an update for next release
Thanks for looking Hax! 🙂
Hello Hax,
Any news on the “multiple” issue?
We see “multiple” but canNOT see the posts/pages the file is attached to.
Any updates coming up?
Thank you for your time and work 🙂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: http://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: http://www.sebastien-meric.com Requires at least: 3.1.0 Tested up to: 3.2 Copyright 2010-2011 by Sébastien Méric http://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.
arg ! there is a typo and i cannot edit the post no more !
you have to replace
$post_parent
with$args['post_parent']
sorry…
after more tests, i see that the function does not work wery well… so here is a better one :
<?php /* Plugin Name: File Un-Attach Helper Functions Plugin URI: http://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: http://www.sebastien-meric.com Requires at least: 3.1.0 Tested up to: 3.2 Copyright 2010-2011 by Sébastien Méric http://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 $legal_attachments = get_children( $args ); // FileUnattach way to get attachments if ( class_exists( 'FileUnattach' ) ) { $args['meta_key'] = '_fun-parent'; $args['meta_value'] = $args['post_parent']; $args['post_parent'] = ''; $fun_attachments = get_posts( $args ); } $attachments = array_merge( $legal_attachments, $fun_attachments ); // if there are elts in both arrays, then there must be some duplicates. // remove those duplicates ! if ( !empty( $legal_attachments ) && !empty( $fun_attachments ) ) { foreach ( $attachments as &$attachment ) { $attachment = serialize( $attachment ); } $attachments = array_unique( $attachments ); foreach ( $attachments as &$attachment ) { $attachment = unserialize( $attachment ); } } if ( !$attachments ) { return array(); } return $attachments; } ?>
Hello Hax,
Are there any changes regarding theWe see “multiple” but canNOT see the posts/pages the file is attached to.
issue?
We love your plugin and would like to use it again.Thank you
- The topic ‘[Plugin: File Un-Attach] not sure that multiple attachments is working properly’ is closed to new replies.