I have an issue trying to get the current page from WP pagination. Here is my code:
global $wp_query;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
var_dump(get_query_var( 'paged' )); // HERE RETURN 0 EVERYTIME
$args = [
'post_type' => 'post',
'posts_per_page' => 30,
'paged' => $paged
];
$loop = new WP_Query($args);
while ($loop->have_posts()) :
$loop->the_post(); ?>
// code ....
<?php endwhile; ?>
I use this code on a single-page template (and so from a single-page URL). Doing get_query_var( 'paged' );
returns 0.
How to get the current page from a single-page template?
As per documentation: