The problem I'm having is that pagination (which I'm running through a shortcode) is not working as expected. In every paginated page, the results are the same. I've found similar questions about problems such as this one but none of the suggestions I've tried seem to work.
Pagination is showing up correctly, page count is correct and the URL is changing as expected when changing the page but the returned items are always the same in every page.
My current code:
function shortcode_paginated_list() {
$args = array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => '2',
'publish_status' => 'published',
'paged' => '<li>'.( get_query_var('paged') ? get_query_var('paged') : 1).'</li>'
);
$wp_query = new WP_Query($args);
if($wp_query->have_posts()) :
while($wp_query->have_posts()) : $wp_query->the_post();
$result = 'fetching some stuff';
endwhile;
endif;
$big = 999999999; // need an unlikely integer
$paginate = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_text' => __('<i class="fas fa-angle-left"></i>'),
'next_text' => __('<i class="fas fa-angle-right"></i>'),
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'list'
) );
$result .= '<div class="blog-nav">' . str_replace( "<ul class='page-numbers'>", '<ul class="pagination">', $paginate ) . '</div>';
wp_reset_postdata();
return $result;
}
add_shortcode( 'paginated-list', 'shortcode_paginated_list' );
Any help would be greatly appreciated, thanks.
For anyone that might stumble upon this, this seems to be working as expected for some reason:
$the_query =
new WP_Query( array(
'post_type'=>'my_custom_post_type',
'posts_per_page' => '2',
'publish_status' => 'published',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
);
while ($the_query -> have_posts()) : $the_query -> the_post();
$result = 'fetching some stuff';
endwhile;
$big = 999999999; // need an unlikely integer
$paginate = paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'prev_text' => __('<i class="fas fa-angle-left"></i>'),
'next_text' => __('<i class="fas fa-angle-right"></i>'),
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages,
'type' => 'list'
));
$result .= '<div class="blog-nav">' . str_replace( "<ul class='page-numbers'>", '<ul class="pagination">', $paginate ) . '</div>';
wp_reset_postdata();
return $result;