Home / functions.php / List all unattached files in media library
  • List all unattached files in media library

    list-all-unattached-files-in-media-library

    Adding the first snippet to the functions.php of your wordpress theme then add the second snippet into your wordpress template. Once added this snippet will display thumbnails of unattached image files and links to other file types.

    wordpress snippet : PHP

    <>
    function get_attachment_files(){
    $args = array(
        'post_type' => 'attachment',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => 0
    ); 
    $attachments = get_posts($args);
    
     if ($attachments) {
        foreach ($attachments as $post) {
            setup_postdata($post);
            the_attachment_link($post->ID);
        }
     }
    }
    

    wordpress snippet : PHP

    <>
    <? get_attachment_files(); ?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    attachment_link, get_post, get_posts, setup_postdata,
  • http://www.facebook.com/Sonnet01 MD Ariful Islam Sonnet

    Thanks sir

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks