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?

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.