WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 the following query, what it does is get a list of "Books" (custom post type). This list is displayed on a page which also has a small form with a dropdown populated with the terms of "Editors" (custom taxonomy). When a user chooses an "Editor", it reloads the page and the query returns the corresponding "Books".

// Taxonomy query
$tax_query = array('relation' => 'AND');
if($_POST['editor']) array_push($tax_query,array('taxonomy' => 't_editor','terms' => array($_POST['editor']),'field' => 'slug'));

// Pagination
if($_POST['reset_pagination'] || !get_query_var('paged')){
    $paged = 1;
}else if (get_query_var('paged')) {
    $paged = get_query_var('paged');

// Query
$myquery = array(
    'post_status' => 'publish',
    'post_type' => 'books',
    'orderby' => 'title',
    'order' => 'ASC',
    'tax_query' => $tax_query,
    'paged' => $paged

As there are many many "Books", I use pagination.

Now, the problem. Lets say I'm on the general list (non-filtered by "Editor"), I have 200 results, with a pagination of ten per page. Let's say I browse until page 8. Then, if I decide to filter my choice by "Editor", the page reloads and displays only those results. The problem is that as I was on page 8, my URL has /page/8/ attached to it.

I found how to reset "paged" to 1 after a filtering has been made (with a hidden "reset_pagination" field on the form), it works and I have the results of page 1 after a filtering, BUT in the URL the pagination (/page/8/) remains.

How can I remove "/page/x/" from the URL ?

Edit : Here's the code for the form

<form action="" method="post" id="filter">
        <?php include(TEMPLATEPATH . '/includes/forms/filter_editors.php'); ?>
        <input type="hidden" name="reset_pagination" value="1"/>
        <input type="submit" class="submit" value="<?php _e('Ok'); ?>" />

share|improve this question
Can you add the code for the form that contains the "Editor" dropdown? I suspect you just need to set the action parameter of the form: make it submit to the URL without the /page/x/, and it will show the first page. If you don't specify an action parameter, it will submit back to the same URL. – Jan Fabry May 6 '11 at 9:06
I posted the form code. You're right, my "action" has no value. – mike23 May 6 '11 at 9:53
up vote 1 down vote accepted

Your form will post back to the URL specified in the action parameter, or to the same URL if you don't specify it. You start at /books/page/8/, so if your action parameter is empty, the resulting URL will also be /books/page/8/. Just fill in the action parameter with /books/, and it should work.

share|improve this answer
Thanks Jan it works, I ended up putting action = "<?php bloginfo('home'); ?>/books/" – mike23 May 6 '11 at 10:19

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.