0

I've used this code https://wordpress.stackexchange.com/a/296517/254438 to add image sizes in media library.

How do I add sorting of image sizes? I know there are plugins but I don't want to use any plugin.

5
  • 1
    this will be quite expensive since the file size is not stored in the database which is necessary to do the sorting/filtering. You would need to put that data in the database likely in the attachments post meta, rather than reading it straight from the filesystem every time
    – Tom J Nowell
    Commented Nov 28 at 17:33
  • Bummer, thanks for reply though.
    – Vaughn
    Commented Nov 28 at 18:10
  • 1
    not impossible though, but I question why you'd need this kind of functionality to begin with, especially when you can enforce limits on upload filesize, or that every image size added means an additional file on the filesystem so the size of the original file is not the whole story anyway. What lead you down this road? Perhaps there are better things that can be done!
    – Tom J Nowell
    Commented Nov 28 at 19:16
  • Images are already uploaded. I've to now search them and reduce their sizes one by one. Sorting would speed it up.
    – Vaughn
    Commented Nov 28 at 19:19
  • Honestly, having done this in the past, I have found it significantly quicker to do it via FTP. You can sort there by file size and see which ones are large. If it's optimization, complete and total optimization you're after, you could check out the TinyPNG.com plugin. Commented Dec 4 at 16:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.