1

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?

Mtxz
  • 3,749
  • 15
  • 29

1 Answers1

2

As per documentation:

For getting the current pagination number on a static front page (Page template) you have to use the 'page' query variable:

<?php $page = (int)get_query_var( 'page', 1 );  ?>
<h1>Currently Browsing Page <?php echo $page; ?> On a static front page</h1>
Mtxz
  • 3,749
  • 15
  • 29