Is there a way to show/hide attachments in my case images on a post.
What I want is to mark an image as "hidden" and then only show it to the admin and hide hidden images from a normal user I know how to use
get_posts to get attachments also how to check if user is an admin just want to know if there is somewhere a field or table where I can store a flag that the attachment is hidden or if there is any "best practice" for this.
Essentially I have an post with attached images and I display a gallery of the images on a page as a custom post type and I want is to show the “hidden” images to the admin but not to a user lower then admin. Atm. I am using:
$args = array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'post_status' => null, // Change the number of images to show in the gallery below 'numberposts' => 999, ); $attachments = get_posts($args);
To retrieve the attachments
I tried wp_delete_attachment witch confuses me because according to *WP documentation: *
function wp_delete_attachment( $post_id, $force_delete = false ) it has a parameter that does not permanently delete the attachment
bool $force_delete: Whether to bypass trash and force deletion. Defaults to false.
but when I used it as:
wp_delete_attachment( $item,false );
$itembeing the id for the attachment
it deleted the image from the uploads folder. If the
wp_delete_attachment function works as intended I would like to know how to query the deleted attachments that are bound to the post. So that the admin user has a chance to "restore" the image
Hope someone can help.