1

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">
<ol>
    <li>
        <?php include(TEMPLATEPATH . '/includes/forms/filter_editors.php'); ?>
    </li>
    <li>
        <input type="hidden" name="reset_pagination" value="1"/>
        <input type="submit" class="submit" value="<?php _e('Ok'); ?>" />
    </li>
</ol>

2
  • 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
    Commented May 6, 2011 at 9:06
  • I posted the form code. You're right, my "action" has no value.
    – mike23
    Commented May 6, 2011 at 9:53

1 Answer 1

2

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.

2
  • Thanks Jan it works, I ended up putting action = "<?php bloginfo('home'); ?>/books/"
    – mike23
    Commented May 6, 2011 at 10:19
  • Thanks @Jan i have to go back to html school. Commented Mar 10, 2019 at 19:04

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.