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 want to use a dropdown to sort a list of posts in WordPress. The results will display on multiple pages. So how do I pass the query on to the second, third, fourth, etc. pages?

Here's an example of my form.

<form method="post" id="order">
  <select name="sort" onchange='this.form.submit()'>
    <option value="">Sort by</option>  
    <option value="zip">Sort by Zip Code</option>
    <option value="type">Sort by Property Type</option>

Thank you,


share|improve this question

Use sessions:


if( isset( $_POST['order'] ){
  $order = filter_input( INPUT_POST, 'order', FILTER_SANITIZE_STRING );

   if( $order )
    $_SESSION['order'] = $order;


if( isset( $_SESSION['order'] )
  $order = $_SESSION['order'];
share|improve this answer
I'm new to PHP. What would I put in INPUT_POST and FILTER_SANITIZE_STRING? Is this the entire code or is there more? Thanks. – user23898 Dec 7 '12 at 19:49
INPUT_POST and FILTER_SANITIZE_STRING are php constants. Please read the php-manual for filter_input – Ralf912 Dec 8 '12 at 13:32

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.