Hide old attachments from wp media library

You can adjust the attachment query in the media library popup, through the ajax_query_attachments_args filter.

Here are two PHP 5.4+ examples:

Example #1:

Show only attachments that where uploaded during the last 24 hours:

/**
 * Media Library popup 
 * - Only display attachments uploaded during the last 24 hours:
 */
add_filter( 'ajax_query_attachments_args', function( $args )
{
   $args['date_query'] = [['after' => '24 hours ago', 'inclusive' => true ]];
   return $args;
} );

Example #2:

Show only attachments that where uploaded during the last 24 hours by the current user:

/**
 * Media Library popup
 *    - Only display attachments uploaded during the last 24 hours by the current user:
 */
add_filter( 'ajax_query_attachments_args', function( $args )
{
   $args['author']     = get_current_user_id();
   $args['date_query'] = [['after' => '24 hours ago', 'inclusive' => true ]];
   return $args;
} );

Leave a Comment