You appear to be trying to paginate the $all_work
query data, but your pagination code is using the $wp_query
data…
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
… for reasons unknown to me.
If you want to paginate $all_work
you need to use the $all_work
data. The data in $wp-query
is not going to be correct. I suspect it is this mixing of queries that is causing the trouble, and I suspect a similar mixing up of queries that is the reason the code in suggested duplicate isn’t working for you.
Something like this should work:
$page = (!empty($_GET['myp'])) ? $_GET['myp'] : 1;
$per_page = 1;
$base = get_queried_object();
// var_dump($base);
if (null === $base) {
$base = site_url();
} else {
$base = get_permalink($base->ID);
}
// $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$all_work = new WP_Query(array(
'post_type' => 'page',
// 'tax_query' => array(
// array(
// 'taxonomy' => 'type',
// 'field' => 'slug',
// 'terms' => array('case-study', 'portfolio')
// ),
// ),
'posts_per_page' => $per_page,
'orderby' => 'title',
'order' => 'ASC',
'update_post_term_cache' => false,
'nopaging' => false,
'paged' => $page
)
);
$total = $all_work->found_posts;
var_dump($total);
while ( $all_work->have_posts() ) {
$all_work->the_post();
the_title(0);
}
$page_args = array(
'base' => $base.'%_%',
'format' => '?myp=%#%',
'total' => ceil($total / $per_page),
'current' => $page,
'show_all' => True,
'end_size' => 1,
'mid_size' => 1,
'prev_next' => True,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain',
);
echo '<br/>';
echo paginate_links($page_args);
That is generic code, as I don’t have your data on my server, but it should be obvious what needs to be changed.