0
I’m trying to capture the query string paged
on the main page to call a component and load the data. However, its return is always 0
.
When I use this component on other pages, it works normally.
URL structure with Query String
Component capturing the query string
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
Main page calling the component
<section class="col-lg-8 col-xl-9 order-1 order-lg-2">
<h2 class="sr-only">Posts recentes</h2>
<?php get_template_part('components/content', 'posts'); ?>
</section>
Return of get_query_var('paged')
inside the main page
0
I don’t usually use Wordpress but I believe it is not a complex mistake.
But in my case I would have to return the value that is in the URL, it is not?
– Victor Hugo
So the value before being in the URL is in the query. But depending on how you set up your query, paging can behave like a static page. In this case you would have to take the value of page instead of paged. Example:
$page = (get_query_var('page')) ? get_query_var('page') : 1;
– user11917