Created
March 3, 2017 19:08
-
-
Save solid-pixel/1782a1d76f272118e506d2e84acbae4b to your computer and use it in GitHub Desktop.
Replace WP Gallery with The Grid plugin gallery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*------------------------------------*\ | |
REPLACE WP GALLERY WITH THE_GRID PLUGIN | |
\*------------------------------------*/ | |
$GLOBALS['the_grid_gallery'] = 'Gallery'; // add your grid name here | |
// remove the native gallery shortcode | |
remove_shortcode('gallery'); | |
// redeclare the gallery shortcode | |
add_shortcode('gallery', 'the_grid_gallery_shortcode'); | |
function the_grid_gallery_shortcode($ids) { | |
global $tg_gallery_ids; | |
// get the gallery IDs and store them globally | |
$tg_gallery_ids = explode(',',$ids['ids']); | |
// show an existing grid | |
return The_Grid($GLOBALS['the_grid_gallery']); | |
} | |
function my_query_args($query_args, $grid_name) { | |
// get the previously stored gallery IDs | |
global $tg_gallery_ids; | |
// if gallery IDs and previous grid used for the gallery shortcode | |
if ($grid_name == $GLOBALS['the_grid_gallery'] && $tg_gallery_ids) { | |
// all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query) | |
// rebuild the query arg to display a gallery of images | |
$query_args['post_type'] = 'attachment'; | |
$query_args['posts_per_page'] = count($tg_gallery_ids); | |
$query_args['post_status'] = 'inherit'; | |
$query_args['post__in'] = $tg_gallery_ids; | |
$query_args['post__not_in'] = null; | |
$query_args['tax_query'] = null; | |
$query_args['meta_key'] = null; | |
$query_args['meta_query'] = null; | |
} | |
// return the query args (modified or not) | |
return $query_args; | |
} | |
add_filter('tg_wp_query_args', 'my_query_args', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment