1. I have a custom "Stock Photos" post type.
  2. Images that are attached to a "Stock Photo" are given a meta key of is_stock_photo = 1.
  3. I have logic that makes it so on the "Media" screen, images with that meta key are excluded from the results.

I would like to also exclude those results in the media upload frame, but only on the media screen. If you are on the stock photos custom post type, I want exactly the opposite - only stock photos appear in the media uploader.

So I have the logic to hide or show them in pre_get_posts. But I can't identify if I am on the stock photos post type screen, or editing a page. The media uploader is driven through AJAX and so I can't check the URL and the request variables don't help identify the page either.

I would like to use some javascript to add custom $_GET variable in the ajax event that is fired by the media uploader.

Here is what the default ajax call includes (plus a field from ACF, I want what they added basically):


I would like to inject my own, such as:

query[show_stock_photos]: (1 or 0)

I've done some research but it's all JS. WordPress documentation barely includes anything about the media uploader. All I know is the answer probably lies in the wp.media object that is accessible in the js console, but I can't find any more clues.

1 Answer 1


My first instinct was to find _acfuploader in ACF code to see how they are doing it. Unfortunately the latest version doesn't seem to have any occurrences of acfuploader.

The second thing I thought of was the wp_get_referer function. You could use it to see where the ajax request came for. Then you could get the post ID from the query string, get the post type and make a decision based on the value you obtained.

However the HTTP referrer can easily be spoofed so you will have to consider the security implications of using it in your code. However, in this scenario the user doesn't have much to gain from spoofing HTTP referrer so I think it is a viable solution.

Your Answer

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

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