I have my search set up with a page called 'search' and a template called 'searchpage.php'.

When I visit 'domain.com/search?s=term' the URL changes to 'domain.com/search/?s=term'

To solve this and make it work I used:

add_rewrite_endpoint( 'search', EP_ALL );

However, my pagination links im creating use a URL structure of:


WP changes this URL to:


Which still shows a search page but the pagination doesn't work as it would if it kept the normal paged=x.

Any advice?

1 Answer 1


If your are using a custom template I assume you are using a custom loop so first populate $paged.

<?php $max_posts = get_option('posts_per_page '); ?>
<?php global $paged; ?>
  if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
  elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
  else { $paged = 1; }  

Then use $paged in your own loop;

  <?php $args = array('posts_per_page' => $max_posts,
                      'paged' => $paged ); ?>
  <?php $query = new WP_Query( $args ); ?>          
  <?php if ( $query->have_posts() ) : ?>            
    <?php while ( $query->have_posts() ) : $query->the_post(); ?>        
      Your code here
    <?php endwhile ?>    
  <?php endif; ?>  

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.