Skip to content

Instantly share code, notes, and snippets.

@Firsh
Last active December 15, 2020 11:13
Show Gist options
  • Save Firsh/c7f6dbdca9097e0c01db38d9b8c9e9dd to your computer and use it in GitHub Desktop.
Save Firsh/c7f6dbdca9097e0c01db38d9b8c9e9dd to your computer and use it in GitHub Desktop.
JIG galleries by custom meta
<?php
//The new filters are called 'jig_media_library_query_args' and 'jig_recent_posts_query_args'
// Media Library queries
add_filter('jig_media_library_query_args', 'jig_change_media_library_query', 10, 2);
function jig_change_media_library_query ($args, $atts) {
$args['meta_key'] = 'your_custom_field_name'; // some start with an underscore
$args['meta_value'] = 'field_value';
return $args;
}
// Recent Posts queries
add_filter('jig_recent_posts_query_args', 'jig_change_recent_posts_query', 10, 2);
function jig_change_recent_posts_query($args, $atts) {
$args['meta_query'][] = [
'key' => 'your_custom_field_name', // some start with an underscore
'value' => 'field_value'
];
return $args;
}
// $atts can be used to identify just a particular JIG to apply these on
function jig_change_recent_posts_query($args, $atts) {
if ($atts['gallery'] === '1595') { // where 1595 is the JIG ID (created from the Grids page)
$args['meta_query'][] = [
'key' => 'your_custom_field_name',
'value' => 'field_value'
];
}
return $args;
}
// If you are using shortcodes and not the Grids page, the $atts includes every shortcode attribute
// return $args; must be present in all cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment