I’ve got code in my functions.php which parses the WP uploads folder and lists all images it finds there. Is it possible to place a filter here that would exclude any image that is already “attached” to a post?

eg: “List all images in folder “uploads” where image is not found in (attached images)”

1 Answer
1

Under Media / Edit, there’s a means to list them, so I suggest you reuse the existing API.

Else, a general method, which works anywhere, is to run a db query with a left join:

select ID
  from foo
left join bar
    on whatever
 where condition
   and bar.ID is null;

Leave a Reply

Your email address will not be published. Required fields are marked *