get_pagination_links
is looking at $wp_query
, whereas you want pagination for your query object named $loop
. So instead, use paginate_links
Something similar to this code, which is based on get_pagination_links
, alebit with wp-query swapped out for your loop query object:
$endsize = $midsize = 1;
$type="plain";
$loop->query_vars['paged'] > 1 ? $current = $loop->query_vars['paged'] : $current = 1;
// Sanitize input argument values
if ( ! in_array( $type, array( 'plain', 'list', 'array' ) ) ) $type="plain";
$endsize = (int) $endsize;
$midsize = (int) $midsize;
// Setup argument array for paginate_links()
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'total' => $loop->max_num_pages,
'current' => $current,
'show_all' => false,
'end_size' => $endsize,
'mid_size' => $midsize,
'type' => $type,
'prev_next' => false,
'paged' => $loop->query_vars['paged']
);
echo paginate_links( $pagination );
Finally you’ll need to grab the paged
URL variable via $_GET, do a tad sanitisation ( check it’s a number and it’s set ), then put it into your WP_Query
args array