M
M
Muvka2018-04-24 09:55:24
WordPress
Muvka, 2018-04-24 09:55:24

Why is get_query_var('page') not returning anything?

There is a blog page - static. I'm trying to set up pagination, but when I go through the pages, the same posts are displayed.

$paged = (get_query_var('page')) ? get_query_var('page') : 1;

$paged always returns 1 because get_query_var('page') returns nothing. At least on the first, at least on the second page. What's wrong?
On the first page get_query_var('page') returns 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Muvka, 2018-04-24
@Muvka

In general, I made a crutch suitable for myself. The site is simple overall. Just for paged, I isolated the page number from the address bar and assign it to paged. Who knows, let him say what problems can arise?

$paged = 1;

$req_uri = array_reverse(explode('/', $_SERVER['REQUEST_URI']));
foreach ($req_uri as $value) {
   if(is_numeric($value)) {
        $paged = $value;
  break;
   }
}
$args = array (
 'post_type' => 'post',
 'post_status' => array( 'publish' ),
 'posts_per_page' => '8',
 'paged' => $paged
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question