Skip to content

Instantly share code, notes, and snippets.

@marcelo2605
Created January 4, 2019 13:24
Show Gist options
  • Save marcelo2605/a8d416c8d7dfd0d8b188af4e64021c2c to your computer and use it in GitHub Desktop.
Save marcelo2605/a8d416c8d7dfd0d8b188af4e64021c2c to your computer and use it in GitHub Desktop.
Pagination with custom wp_query
// more options here: https://codex.wordpress.org/Function_Reference/paginate_links
public static function getPagination($pages = null)
{
$args = array(
'prev_next' => false,
'type' => 'list'
);
if ($pages) {
$args['total'] = $pages;
}
$html = paginate_links($args);
return $html;
}
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'obra',
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
);
$posts = new \WP_Query($args);
$pages = $posts->max_num_pages;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment