How to limit number of images being printer out in “Set Featured Image” pop up?

I have wordpress web site which contains over 150 000 images and when you click on “Set Featured Image” whole server slows down. Another thing is that it take a really long time to load images.

Is there any filter/action/hook to add pager or to just show last 10 images.

Another question is how to optimize whole thing (maybe images sort by subfolders with some plugin) so it can work

1 Answer
1

Update 1:

After dived into core AJAX call, this filter will only happen on post.php page:

add_filter('ajax_query_attachments_args', function($query){
    if ( isset($_POST['post_id']) && !empty($_POST['post_id']) ) {
        $query['posts_per_page'] = 10; // output 10 images only.
    }
    return $query;
});

  1. You can use ajax_query_attachments_args filter:
add_filter('ajax_query_attachments_args', function($query){
    $query['posts_per_page'] = 10; // output 10 images only.
    return $query;
});
  1. Because of querying attachments happens in core and using AJAX, I don’t think we can optimize the whole thing.

Leave a Comment