I have that rare thing, a group of contributors who worry too much about copyright. To encourage them to use the media library, I want to provide them with an alternative version of the library that only shows licensed images. I label these with an attachment category, 'Licensed Stock Images'.

I thought I could make a copy of upload.php that's already filtered by Att. Category = Licensed Stock Images but couldn't work out how to pre-set the filter. I also wondered whether there's a URI query string that might do the job.

Any clues?

  • 1
    you should not ever even dream about changing wordpress core file. please edit your question, and explain what is that you want to implement instead of how you think it should be implemented – Mark Kaplun Sep 4 '17 at 1:01
  • Done. Sorry it wasn't clear. – cherryaustin Sep 4 '17 at 16:11
  • If you search for pre_get_posts with "media library", you'll find some related answers that might get you started. – Milo Sep 4 '17 at 23:47

Thanks to Milo for the pointer. I'm going to have to work on my application, but the main point is this filters the media library as required.

function only_licensed_images($query){

    global $pagenow;

    if( ! in_array( $pagenow, array( 'upload.php', 'admin-ajax.php' ) ) )

        $query->set( 'attachment_category', 'Licensed Stock Images' );
  • This is probably the right way to go, but you should be careful about how you detect that it is time to set the query. Right now it seems too broad at least on the ajax side, and might cause strange side effect depending on what kind of other ajax is being done on your site. – Mark Kaplun Sep 5 '17 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.