Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
  </select>
</form>

Thank you,

John

share|improve this question
add comment

1 Answer 1

Use sessions:

<?php
session_start();

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
add comment

Your Answer

 
discard

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.