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 a custom template with a drop-down that filters posts by category. I do it by making the form post to the page itself and then catching the argument and using it in a query (see code below).

Here's the bummer: if you navigate to page 2 (for example) and then use the filter, the URL still contains the /page/2/ bit, and you can sometimes end up with zero posts visible if there are less than a page's worth of results, since the new results all on page 1 and you're stuck on page 2. Tried unsetting the paged variable, to no avail. How can I send the user back to first page every time they use the filter?

<form action="" method="POST">
        <select id="food-type" name="food_type" class="selectBox">
            <option value="0">Select One:</option>
            <option value="meat">Meat</option>
            <option value="salads">Salads</option>
            <option value="vegetarian-entrees">Vegetarian Entrees</option>
        <button type="submit" class="search">Search</button>

I process its contents as follows:

global $post;
global $query_string;

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
    'post_status'      => 'publish',
    'post_type'        => 'recipe',
    'suppress_filters' => false,
    'paged'   => $paged

if(isset($_POST['select_food_type']) && !empty($_POST['select_food_type']) ) {
    $args['food_type'] = $_POST['select_food_type'];
share|improve this question
up vote 0 down vote accepted

Perhaps set your form's action to point to the first page of paged results, rather than the default (empty) of the current page.

<form action="_URL_to_first_page_" method="POST">

Keep in mind the URL is determined on the client side in the case of an empty action.

share|improve this answer
indeed! just got it myself but will mark your answer as correct. thanks! – montrealist Nov 21 '12 at 19:41

Here's the solution. Make sure the form posts to the proper page every time instead of posting to the current URL.

<form action="<?php echo get_permalink(); ?>" method="POST">
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.