This is what I use in all my other pages that require a pagination.

<?php endwhile; ?> 

global $wp_query;

$total_pages = $wp_query->max_num_pages;

if ($total_pages > 1){

  $current_page = max(1, get_query_var('paged'));

  echo paginate_links(array(
      'base' => get_pagenum_link(1) . '%_%',
      'format' => '/page/%#%',
      'current' => $current_page,
      'total' => $total_pages,
      'before_page_number' => '<div class="pagination-navigation row">',
      'after_page_number' => '</div>'


<?php else: ?>

        <p>We cannot mach any products with what you have entered in the search bar above</p>

    <?php endif; ?>

That will give me the number of pages the paginations require such as

1 2 3 4 5

Now the problem is when I use that code to add pagination to my search page it literally searches my searchword/pages/2.

Like if I search for HONDA I will get the first 10 results for HONDA. If I add that paginations code to get all the results and go to page 2, it will tell me that I have searched for HONDA/PAGE/2 and there for NOT giving me any search results for the second page and so on.

For some reason it's adding the permalink to my search term and searching that if that makes any sense.

Now I have narrowed down the problem and it seems it's just my pagination code above thats the problem and I can't find out how to get it to work properly in the search page because I don't want a pagination to say next or previous. I want a numbered paginations which is why I'm trying to get that code to work in the search page like it does in my taxonomy.php for all my products.

  • Related problem and possible duplicate – Pieter Goosen Dec 2 '14 at 6:39
  • Pieter to the rescue again! thanks a lot Pieter I found out from that post I just had to change my base to 'base' => @add_query_arg('paged','%#%') – Lucas Santos Dec 2 '14 at 8:17
  • Glad that link helped. :-) – Pieter Goosen Dec 2 '14 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.