This is the jig_media_library_query_args filter for developers.
It allows advanced users to influence the query for various sources based on media library. It filters the four Media Library queries in JIG, these are:
- Normal galleries with a list of IDs.
- Galleries based on tags, categories, or custom taxonomies, including the ones from Media Library Assistant.
- Real Media Library galleries.
- Images from multiple posts at the same time.
A helpful use case would be switching comma-separated terms (tags, categories, custom taxonomies) to the AND operator, meaning all terms must be present on an image for it to be displayed. There is no other way to do that presently (nor shortcuts based on plus signs instead of commas). Currently, media library queries use IN operator (match any of the listed terms). Another use would be showing grids based on custom meta keys such as those created with ACF. The filter uses the query arguments $args, and the shortcode attributes $atts to enable identifying a single grid.
Grids based on custom meta key/value on the images
1 2 3 4 5 6 7 8 9 | add_filter('jig_media_library_query_args', 'add_meta_to_jig_media_library_query', 10, 2); function add_meta_to_jig_media_library_query($args, $atts) { if ($atts['gallery'] === '1234') { $args['meta_key'] = '_custom_meta_name'; $args['meta_value'] = 'something'; } return $args; } |
Then, we insert our additions to the meta_key and meta_value. If you omit the latter you can get images that have any value but they must have the key. Sometimes the key starts with an underscore, other times it doesn't, so try both.
Depending on what you are trying to achieve, consider creating grids based on tags, categories, custom taxonomies, those are usually easier to handle and set up.
Switching tags, categories, and custom taxonomies to AND operator
[$justified_image_grid image_categories=humans,animals]
And you want to show images that have human and an animal in them, but not a lone wolf.
1 2 3 4 5 6 | add_filter('jig_media_library_query_args', 'add_and_to_jig_media_library_query', 10, 2); function add_and_to_jig_media_library_query($args, $atts) { $args['tax_query'][0]['operator'] = 'AND'; return $args; } |
The code is very similar to how you'd add the AND to the recent posts queries. All taxonomies, both native and custom ones use the tax_query behind the scenes of JIG, for media library content. It doesn't have a default value, so the only thing in it should be your choice to include humans and animals. By inserting the operator in index 0, we can be sure that we are connecting humans and animals using an AND word. The index changes from 0 to 1 or 2 if you utilize more than one taxonomy at the same time. You could use tags, categories and a custom taxonomy, all three at the same time. The more you use, the less images you'll see in the grid, and between these there is an AND relation by default, which is meaningful in most cases. However, on their individual levels of comma separated terms, you can further narrow the query by using this method.