WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have using the Wordpress paginate_links() to build a paginator on a custom archive template for a custom post type. My site uses permalinks:

<?php echo paginate_links(array(
    'base' => get_pagenum_link(1) . '%_%',
    'current' => max(1, get_query_var('paged')),
    'format' => 'page/%#%',
    'total' => $wp_query->max_num_pages,
)); ?>

This works fine until I try to add query string vars to build a custom search string when the paginator echoes:


Instead of:


and so on... How can I get the correctly formatted URLs?

share|improve this question
What exactly is adding those vars? – Rarst Oct 21 '13 at 21:05
up vote 4 down vote accepted

Seems that the query string is coming from the base argument call to get_pagenum_link() so I have removed the query string component and re-add it with 'add_args'. Like so:

<?php echo paginate_links(array(
     'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%',
     'current' => max(1, get_query_var('paged')),
     'format' => 'page/%#%',
     'total' => $wp_query->max_num_pages,
     'add_args' => array(
         's' => get_query_var('s'),
         'post_type' => get_query_var('post_type'),
 )); ?>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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