My Seach Page URLs:
Here my custom search page:
<?php
if($_GET['search_text'] && !empty($_GET['search_text']))
{
$text = $_GET['search_text'];
}
else
{
$text = urldecode( get_query_var('search_text') ) ;
}
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="searchpage-container">
<div class="searchpage-filter-container">
<span>Arama Sonuçları:</span>
</div>
<div class="product-container">
<?php
$my_products = array( 2085, 4094, 2900, 4072, 131 );
global $paged;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'product',
'posts_per_page' => 2,
'paged' => $paged,
'post__in' => $my_products
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
$total_pages = $loop->max_num_pages;
if ($total_pages > 1){
/* $current_page = max(1, get_query_var('paged')); */
$wp_query->query_vars['paged'] > 1 ? $current_page = $wp_query->query_vars['paged'] : $current_page = 1;
echo $wp_query->query_vars['paged'];
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
}
wp_reset_postdata();
?>
</div>
</div>
</main><!-- #main -->
</div><!-- #primary -->
My pagination links are created fine, but I always see the page No 1 because somehow query_vars['paged']
is emtpy.
I have seen Preserving Search Page Results and Pagination
section on this page , but couldn't figure it out how to use it, but I don't think this is really needed in my case.
EDIT 1 (Response to comment from J.D.):
That function you mentioned only returns an array of product IDs, to simplify my code, I removed my function add a static array instead.
aws_search_byozan()
? Could it be overwriting thepaged
query var? If youget_query_var( 'paged' )
before calling that, what is the value?aws_search_byozan()
from code. Problem still exists.