This is the jig_recent_posts_query_args filter for developers.
It allows advanced users to influence the recent posts query. For example, you could show grids based on custom post meta key and value pairs, or remove the default "only in stock" WooCommerce behavior, add an AND relationship between your custom taxonomy terms, etc. It uses the query arguments $args, and the shortcode attributes $atts to enable identifying a single grid.
Grids based on custom post meta key/value
1 2 3 4 5 6 7 8 9 10 11 | add_filter('jig_recent_posts_query_args', 'change_jig_recent_posts_query', 10, 2); function change_jig_recent_posts_query($args, $atts) { if ($atts['gallery'] === "1234") { $args['meta_query'][] = [ 'key' => 'your_custom_field_name', 'value' => 'field_value' ]; } return $args; } |
Then, we insert our additions to the meta_query and we are making an assumption it exists. It often does, if you are not using a placeholder image for recent posts (it's a setting), and/or when using WooCommerce to show only in-stock items (more on that below). If it doesn't exist, just remove the [] from it and create an array of arrays (two opening and closing squery brackets instead of one, around the key value pair). Replace key value pair's example strings with your own.
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.
Showing WooCommerce products that are out of stock
1 2 3 4 5 6 7 8 | add_filter('jig_recent_posts_query_args', 'change_jig_recent_posts_query', 10, 2); function change_jig_recent_posts_query($args, $atts) { $args['meta_query'] = [ ['key' => '_thumbnail_id'] ]; return $args; } |
Using an AND relationship operator with your custom taxonomy terms
This assumes you use a shortcode like this in the first place:
[$justified_image_grid recent_posts=yes recents_filter_tax=animals recents_filter_term=cat,dog]
And you want to show posts that are about a cat and a dog, but not those that only have one of these animals.
1 2 3 4 5 6 | add_filter('jig_recent_posts_query_args', 'add_and_to_jig_recent_posts_query', 10, 2); function add_and_to_jig_recent_posts_query($args, $atts) { $args['tax_query'][0]['operator'] = 'AND'; return $args; } |
We are no longer bothering the meta_query as previously seen, rather this is the tax_query. It doesn't have a default value, so the only thing in it should be your choice to include cats and dogs. By inserting the operator in index 0, we can be sure that we are connecting cats with dogs with an AND word, behind the scenes.
Please note that if you are using the native category or tag taxonomies, you don't need the custom code! You can just use a + (plus sign) between them instead of the commas, and JIG will handle the rest and pass them on to WP Query in the appropriate way. This is only for the Recent posts feature, and not for normal media library image queries.