Home Forums Backend Issues (wp-admin) Show specific category in Gallery field Reply To: Show specific category in Gallery field

  • WP does not natively support taxonomies for media. I say this because ACF is not likely to support anything that is not supported by core WP.

    To do this a new field type, maybe, for the gallery (an the image field) would need to be built that supports the method that you’re using to add these taxonomies to media posts.

    You may also be able to modify the gallery field? I don’t know.

    First you would need a new field setting to choose a category. You might be able to do this using a filter on acf/render_field_settings. But the media list is done with an AJAX query and without altering the JS involved I don’t know if there is a way to send the value of your setting in the query. There may be information in $_POST that can be used to figure out what field is being loaded, big question mark.

    After that??? I don’t know. I’ve followed, or tried to follow the code, but quite honestly, I don’t see how it works. I do know that it ties into the built in WP media popup dialog. You may be able to limit it using a WP ajax_query_attachment_args filter. When this filter is run you may be able to set the category, and like I said, there may be values in $_POST that tell you what field the query is being done for and then alter the query based on those values.

    Here are some links to simple examples of this filter that limit media to those uploaded by a specific user

    I would start with this filter and I would figure out what values I have available to work with.

    // this is a simple function that will log values sent during an ajax query
    // values are added to your error log file
    add_filter( 'ajax_query_attachments_args', 'log_attachment_query' );
    function log_attachment_query($query) {
      return $query;

    This topic has come up in the past here, multiple times, unfortunately, I cannot find it or remember if a solution was ever found.