Created
January 4, 2019 13:24
-
-
Save marcelo2605/a8d416c8d7dfd0d8b188af4e64021c2c to your computer and use it in GitHub Desktop.
Pagination with custom wp_query
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
// 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; | |
} |
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
$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