0

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

2

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'];
|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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.